summaryrefslogtreecommitdiff
path: root/usr/src/ucbcmd
diff options
context:
space:
mode:
authorstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
committerstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
commit7c478bd95313f5f23a4c958a745db2134aa03244 (patch)
treec871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/ucbcmd
downloadillumos-gate-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz
OpenSolaris Launch
Diffstat (limited to 'usr/src/ucbcmd')
-rw-r--r--usr/src/ucbcmd/Makefile185
-rw-r--r--usr/src/ucbcmd/Makefile.ucbcmd103
-rw-r--r--usr/src/ucbcmd/Makefile.ucbcmd.6444
-rw-r--r--usr/src/ucbcmd/Makefile.ucbtarg38
-rw-r--r--usr/src/ucbcmd/basename/Makefile44
-rw-r--r--usr/src/ucbcmd/basename/basename.c48
-rw-r--r--usr/src/ucbcmd/biff/Makefile42
-rw-r--r--usr/src/ucbcmd/biff/biff.c94
-rw-r--r--usr/src/ucbcmd/cc/Makefile45
-rw-r--r--usr/src/ucbcmd/cc/cc.sh141
-rw-r--r--usr/src/ucbcmd/chown/Makefile47
-rw-r--r--usr/src/ucbcmd/chown/chown.c244
-rw-r--r--usr/src/ucbcmd/df/Makefile44
-rw-r--r--usr/src/ucbcmd/df/df.sh74
-rw-r--r--usr/src/ucbcmd/du/Makefile44
-rw-r--r--usr/src/ucbcmd/du/du.sh32
-rw-r--r--usr/src/ucbcmd/echo/Makefile44
-rw-r--r--usr/src/ucbcmd/echo/echo.c43
-rw-r--r--usr/src/ucbcmd/expr/Makefile44
-rw-r--r--usr/src/ucbcmd/expr/expr.y398
-rw-r--r--usr/src/ucbcmd/fastboot/Makefile50
-rw-r--r--usr/src/ucbcmd/fastboot/fastboot.sh45
-rw-r--r--usr/src/ucbcmd/fasthalt/Makefile50
-rw-r--r--usr/src/ucbcmd/fasthalt/fasthalt.sh45
-rw-r--r--usr/src/ucbcmd/file/Makefile49
-rw-r--r--usr/src/ucbcmd/file/file.sh51
-rw-r--r--usr/src/ucbcmd/from/Makefile44
-rw-r--r--usr/src/ucbcmd/from/from.c116
-rw-r--r--usr/src/ucbcmd/groups/Makefile44
-rw-r--r--usr/src/ucbcmd/groups/groups.c101
-rw-r--r--usr/src/ucbcmd/install.d/Makefile62
-rw-r--r--usr/src/ucbcmd/install.d/install.c354
-rw-r--r--usr/src/ucbcmd/ld/Makefile49
-rw-r--r--usr/src/ucbcmd/ld/ld.sh77
-rw-r--r--usr/src/ucbcmd/lint.d/Makefile54
-rw-r--r--usr/src/ucbcmd/lint.d/lint.sh77
-rw-r--r--usr/src/ucbcmd/ln/Makefile44
-rw-r--r--usr/src/ucbcmd/ln/ln.c122
-rw-r--r--usr/src/ucbcmd/ls/Makefile49
-rw-r--r--usr/src/ucbcmd/ls/ls.c841
-rw-r--r--usr/src/ucbcmd/mach/Makefile52
-rw-r--r--usr/src/ucbcmd/mkstr/Makefile45
-rw-r--r--usr/src/ucbcmd/mkstr/mkstr.c303
-rw-r--r--usr/src/ucbcmd/mkstr/mkstr.xcl29
-rw-r--r--usr/src/ucbcmd/plot/Makefile226
-rw-r--r--usr/src/ucbcmd/plot/atoplot.c181
-rw-r--r--usr/src/ucbcmd/plot/chrtab.c117
-rw-r--r--usr/src/ucbcmd/plot/crtdriver.c152
-rw-r--r--usr/src/ucbcmd/plot/crtplot.c305
-rw-r--r--usr/src/ucbcmd/plot/debug.c140
-rw-r--r--usr/src/ucbcmd/plot/driver.c168
-rw-r--r--usr/src/ucbcmd/plot/libplot/Makefile49
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/Makefile54
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/aed.h36
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/arc.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/circle.c41
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/close.c36
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/cont.c32
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/erase.c36
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/label.c43
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/line.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/linemod.c45
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/move.c33
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/open.c88
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/point.c41
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/space.c46
-rw-r--r--usr/src/ucbcmd/plot/libplot/aed/subr.c105
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/Makefile54
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/arc.c103
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/bg.h38
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/circle.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/close.c32
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/cont.c29
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/dot.c21
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/erase.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/label.c24
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/line.c33
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/linemod.c21
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/move.c29
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/open.c43
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/point.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/bitgraph/space.c31
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/arc.c24
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/circle.c19
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/close.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/cont.c29
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/dumb.h39
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/erase.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/label.c31
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/line.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/linemod.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/move.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/open.c67
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/point.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/space.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/dumb/subr.c57
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/arc.c57
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/circle.c30
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/close.c32
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/cont.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/erase.c24
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/gigi.h42
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/label.c30
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/line.c32
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/linemod.c79
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/move.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/open.c48
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/point.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/gigi/space.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/Makefile54
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/arc.c63
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/circle.c41
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/close.c29
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/cont.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/erase.c32
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/hp2648.h55
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/label.c40
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/line.c32
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/linemod.c86
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/move.c35
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/open.c59
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/point.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/space.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp2648/subr.c65
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/arc.c59
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/circle.c31
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/close.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/cont.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/erase.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/hp7221.h44
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/label.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/line.c32
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/linemod.c78
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/move.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/open.c52
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/point.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/space.c30
-rw-r--r--usr/src/ucbcmd/plot/libplot/hp7221/subr.c83
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/Makefile57
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/arc.c127
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/charset.c21
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/circle.c21
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/close.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/cont.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/erase.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/imPcodes.h67
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/imp.h27
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/label.c35
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/line.c48
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/linemod.c50
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/move.c23
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/open.c49
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/point.c21
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/scale.c40
-rw-r--r--usr/src/ucbcmd/plot/libplot/imagen/space.c38
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/arc.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/circle.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/close.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/cont.c24
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/dot.c30
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/erase.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/label.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/line.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/linmod.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/move.c24
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/open.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/point.c24
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/putsi.c23
-rw-r--r--usr/src/ucbcmd/plot/libplot/plot/space.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/arc.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/circle.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/close.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/con.h37
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/erase.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/label.c29
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/line.c63
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/linmod.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/move.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/open.c65
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/point.c23
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/space.c29
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300/subr.c130
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/arc.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/box.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/circle.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/close.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/con.h46
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/erase.c25
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/label.c29
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/line.c59
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/linmod.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/move.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/open.c65
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/point.c24
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/space.c28
-rw-r--r--usr/src/ucbcmd/plot/libplot/t300s/subr.c174
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/arc.c122
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/box.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/circle.c21
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/close.c27
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/dot.c20
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/erase.c30
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/label.c26
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/line.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/linemod.c23
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/move.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/open.c22
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/point.c21
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/space.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4013/subr.c61
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/arc.c141
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/box.c41
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/circle.c35
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/close.c41
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/dot.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/erase.c47
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/label.c60
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/line.c36
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/linemod.c51
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/move.c36
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/open.c37
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/point.c36
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/space.c49
-rw-r--r--usr/src/ucbcmd/plot/libplot/t4014/subr.c90
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/Makefile53
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/arc.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/box.c41
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/circle.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/close.c40
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/con.h60
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/dot.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/erase.c39
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/label.c43
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/line.c77
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/linmod.c34
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/move.c36
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/open.c82
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/point.c37
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/space.c41
-rw-r--r--usr/src/ucbcmd/plot/libplot/t450/subr.c148
-rw-r--r--usr/src/ucbcmd/plot/plot.sh43
-rw-r--r--usr/src/ucbcmd/plot/plottoa.c240
-rw-r--r--usr/src/ucbcmd/plot/vfont.h48
-rw-r--r--usr/src/ucbcmd/plot/vplot.c510
-rw-r--r--usr/src/ucbcmd/printenv/Makefile44
-rw-r--r--usr/src/ucbcmd/printenv/printenv.c83
-rw-r--r--usr/src/ucbcmd/ps/Makefile59
-rw-r--r--usr/src/ucbcmd/ps/amd64/Makefile63
-rw-r--r--usr/src/ucbcmd/ps/i386/Makefile66
-rw-r--r--usr/src/ucbcmd/ps/ps.c1189
-rw-r--r--usr/src/ucbcmd/ps/sparc/Makefile66
-rw-r--r--usr/src/ucbcmd/ps/sparcv9/Makefile67
-rw-r--r--usr/src/ucbcmd/req.flg37
-rw-r--r--usr/src/ucbcmd/rusage/Makefile56
-rw-r--r--usr/src/ucbcmd/rusage/rusage.c134
-rw-r--r--usr/src/ucbcmd/sbcp/Makefile68
-rw-r--r--usr/src/ucbcmd/sbcp/mksysent68
-rw-r--r--usr/src/ucbcmd/sbcp/sbcp.s181
-rw-r--r--usr/src/ucbcmd/sbcp/syscalls.list216
-rw-r--r--usr/src/ucbcmd/sed/Makefile55
-rw-r--r--usr/src/ucbcmd/sed/sed.h152
-rw-r--r--usr/src/ucbcmd/sed/sed0.c868
-rw-r--r--usr/src/ucbcmd/sed/sed1.c751
-rw-r--r--usr/src/ucbcmd/shutdown/Makefile62
-rw-r--r--usr/src/ucbcmd/shutdown/shutdown.c745
-rw-r--r--usr/src/ucbcmd/shutdown/shutdown.xcl43
-rw-r--r--usr/src/ucbcmd/stty/Makefile50
-rw-r--r--usr/src/ucbcmd/stty/stty.c731
-rw-r--r--usr/src/ucbcmd/stty/stty.h48
-rw-r--r--usr/src/ucbcmd/stty/sttyparse.c446
-rw-r--r--usr/src/ucbcmd/stty/sttytable.c334
-rw-r--r--usr/src/ucbcmd/sum/Makefile46
-rw-r--r--usr/src/ucbcmd/sum/sum.c65
-rw-r--r--usr/src/ucbcmd/test/Makefile47
-rw-r--r--usr/src/ucbcmd/test/test.c276
-rw-r--r--usr/src/ucbcmd/touch/Makefile48
-rw-r--r--usr/src/ucbcmd/touch/touch.c360
-rw-r--r--usr/src/ucbcmd/tr/Makefile44
-rw-r--r--usr/src/ucbcmd/tr/tr.c178
-rw-r--r--usr/src/ucbcmd/tset/Makefile59
-rw-r--r--usr/src/ucbcmd/tset/tset.c1691
-rw-r--r--usr/src/ucbcmd/tset/tset.delays.h110
-rw-r--r--usr/src/ucbcmd/ucblinks/Makefile63
-rw-r--r--usr/src/ucbcmd/ucblinks/ucblinks.awk214
-rw-r--r--usr/src/ucbcmd/ucblinks/ucblinks.c1456
-rw-r--r--usr/src/ucbcmd/ucblinks/ucblinks.sh234
-rw-r--r--usr/src/ucbcmd/users/Makefile44
-rw-r--r--usr/src/ucbcmd/users/users.c102
-rw-r--r--usr/src/ucbcmd/vipw/Makefile54
-rw-r--r--usr/src/ucbcmd/vipw/vipw.c376
-rw-r--r--usr/src/ucbcmd/whereis/Makefile44
-rw-r--r--usr/src/ucbcmd/whereis/whereis.c348
-rw-r--r--usr/src/ucbcmd/whoami/Makefile50
-rw-r--r--usr/src/ucbcmd/whoami/whoami.c54
319 files changed, 27816 insertions, 0 deletions
diff --git a/usr/src/ucbcmd/Makefile b/usr/src/ucbcmd/Makefile
new file mode 100644
index 0000000000..ca06de2aa9
--- /dev/null
+++ b/usr/src/ucbcmd/Makefile
@@ -0,0 +1,185 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 1989-2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ucbcmd/Makefile
+#
+
+# include global definitions; SRC should be defined in the shell.
+# SRC is needed until RFE 1026993 is implemented.
+include $(SRC)/Makefile.master
+include $(SRC)/ucbcmd/Makefile.ucbcmd
+
+COMMON_SUBDIRS= \
+ basename \
+ biff \
+ cc \
+ chown \
+ df \
+ du \
+ echo \
+ expr \
+ fastboot \
+ fasthalt \
+ file \
+ from \
+ groups \
+ install.d \
+ ld \
+ lint.d \
+ ln \
+ ls \
+ mkstr \
+ plot \
+ printenv \
+ ps \
+ rusage \
+ sed \
+ shutdown \
+ stty \
+ sum \
+ test \
+ touch \
+ tr \
+ tset \
+ ucblinks \
+ users \
+ vipw \
+ whereis \
+ whoami
+
+sparc_SUBDIRS= sbcp
+
+SUBDIRS= $(COMMON_SUBDIRS) $($(MACH)_SUBDIRS)
+
+# commands messaged
+MSGSUBDIRS = biff install.d mkstr rusage shutdown ucblinks
+
+BWOSDIRS=
+
+all:= TARGET= all
+install:= TARGET= install
+clean:= TARGET= clean
+clobber:= TARGET= clobber
+lint:= TARGET= lint
+_msg:= TARGET= _msg
+
+# Since pre-5.0 system users were told to put /usr/5bin in their path to
+# get the 5.0 system behavior, we need this link so that the PATH of
+# /usr/5bin:/usr/ucb:/usr/bin does the right thing. (let's see, without
+# this link, 5.0 behaves like UCB and 4.1 behaves like SysV... I'm so
+# confused...)
+ROOTUSR = $(ROOT)/usr
+S5LINK = $(ROOTUSR)/5bin
+DICTLINK = $(ROOTUSR)/dict
+
+# Symbolic links for source compatibility. Many utilities that
+# were under /usr/ucb in SunOS 4.1, are now in the base; the
+# symbolic links are provided for compatibility.
+LINKDEST= ../bin/$(@F)
+
+BINLINKS= \
+ arch \
+ clear \
+ e \
+ edit \
+ ex \
+ vedit \
+ vi \
+ view \
+ finger \
+ fmt \
+ fold \
+ ftp \
+ head \
+ hostid \
+ hostname \
+ logger \
+ mach \
+ more \
+ page \
+ pagesize \
+ netstat \
+ quota \
+ rcp \
+ rdate \
+ renice \
+ rlogin \
+ rsh \
+ ruptime \
+ rwho \
+ script \
+ tail \
+ talk \
+ tcopy \
+ telnet \
+ tftp \
+ uptime \
+ vacation \
+ vmstat \
+ w \
+ wc \
+ whois \
+ xstr
+
+ROOTBINLINKS = $(BINLINKS:%=$(ROOTBIN)/%)
+
+OTHERLINKS = $(ROOTETC)/termcap \
+ $(ROOTSHLIB)/zoneinfo/posixrules
+
+$(S5LINK) := LINKDEST= bin
+$(DICTLINK) := LINKDEST= share/lib/dict
+$(ROOTBIN)/e := LINKDEST= ../bin/ex
+$(ROOTBIN)/page := LINKDEST= ../bin/more
+$(ROOTBIN)/quota := LINKDEST= ../lib/fs/ufs/quota
+$(ROOTETC)/termcap := LINKDEST= ../usr/share/lib/termcap
+$(ROOTSHLIB)/zoneinfo/posixrules := LINKDEST= US/Eastern
+
+.KEEP_STATE:
+
+.PARALLEL: $(SUBDIRS)
+
+all clean clobber: $(SUBDIRS)
+
+install: $(SUBDIRS) .WAIT rootlinks
+
+# For messaging catalog
+#
+_msg: $(MSGSUBDIRS)
+
+
+
+bwos: $(BWOSDIRS) .WAIT $(SUBDIRS)
+
+$(BWOSDIRS) $(SUBDIRS): FRC
+ @cd $@; pwd; $(MAKE) $(TARGET)
+
+rootlinks: $(S5LINK) $(DICTLINK) $(ROOTBINLINKS) $(OTHERLINKS)
+
+$(S5LINK) $(DICTLINK) $(ROOTBINLINKS) $(OTHERLINKS):
+ $(RM) $@; $(SYMLINK) $(LINKDEST) $@
+
+FRC:
diff --git a/usr/src/ucbcmd/Makefile.ucbcmd b/usr/src/ucbcmd/Makefile.ucbcmd
new file mode 100644
index 0000000000..9e1d52074f
--- /dev/null
+++ b/usr/src/ucbcmd/Makefile.ucbcmd
@@ -0,0 +1,103 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# ucbcmd/Makefile.ucbcmd
+#
+# Definitions common to ucb command source.
+#
+# include global definitions; SRC should be defined in the shell.
+# SRC is needed until RFE 1026993 is implemented.
+
+include $(SRC)/Makefile.master
+
+LN= ln
+CP= cp
+SH= sh
+CHMOD= chmod
+MKDIR= mkdir
+TOUCH= touch
+
+LDFLAGS += $(STRIPFLAG)
+
+FILEMODE= 0555
+LIBFILEMODE= 0444
+ROOTBIN= $(ROOT)/usr/ucb
+ROOTLIB= $(ROOT)/usr/ucblib
+ROOT4LIB= $(ROOT)/usr/4lib
+ROOTETC= $(ROOT)/etc
+ROOTSHLIB= $(ROOT)/usr/share/lib
+ROOTBIN32= $(ROOTBIN)/$(MACH32)
+ROOTBIN64= $(ROOTBIN)/$(MACH64)
+
+ROOTPROG= $(PROG:%=$(ROOTBIN)/%)
+ROOTSHFILES= $(SHFILES:%=$(ROOTBIN)/%)
+ROOTLIBPROG= $(PROG:%=$(ROOTLIB)/%)
+ROOT4LIBPROG= $(PROG:%=$(ROOT4LIB)/%)
+ROOTETCPROG= $(PROG:%=$(ROOTETC)/%)
+ROOTPROG64= $(PROG:%=$(ROOTBIN64)/%)
+ROOTPROG32= $(PROG:%=$(ROOTBIN32)/%)
+
+ISAEXEC= $(ROOT)/usr/lib/isaexec
+
+NX_MAP_i386= $(SRC)/cmd/mapfile_noexdata
+NX_MAP_sparc=
+NX_MAP= $(NX_MAP_$(MACH))
+NES_MAPFILE= $(SRC)/cmd/mapfile_noexstk $(NX_MAP)
+
+# storing LDLIBS in two macros allows reordering of options
+LDLIBS.cmd = $(ENVLDLIBS1) $(ENVLDLIBS2) $(ENVLDLIBS3)
+LDLIBS = $(LDLIBS.cmd)
+
+LDFLAGS.cmd = \
+ $(STRIPFLAG) $(ENVLDFLAGS1) $(ENVLDFLAGS2) $(ENVLDFLAGS3) \
+ $(NES_MAPFILE:%=-M%) \
+ $(PGA_MAPFILE:%=-M%)
+
+LDFLAGS = $(STRIPFLAG) $(LDFLAGS.cmd)
+
+SETRUNPATH= LD_RUN_PATH=/usr/ucblib
+
+$(ROOTBIN)/%: %
+ $(INS.file)
+
+$(ROOTLIB)/%: %
+ $(INS.file)
+
+$(ROOT4LIB)/%: %
+ $(INS.file)
+
+$(ROOTETC)/%: %
+ $(INS.file)
+
+$(ROOTBIN64)/%: %
+ $(INS.file)
+
+$(ROOTBIN32)/%: %
+ $(INS.file)
+
+# Define the majority text domain in this directory
+TEXT_DOMAIN= SUNW_OST_UCBCMD
diff --git a/usr/src/ucbcmd/Makefile.ucbcmd.64 b/usr/src/ucbcmd/Makefile.ucbcmd.64
new file mode 100644
index 0000000000..1cf0a27688
--- /dev/null
+++ b/usr/src/ucbcmd/Makefile.ucbcmd.64
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# ucbcmd/Makefile.cmd.64
+#
+# This makefile contains the compiler fiddling needed to build
+# 64-bit utilities.
+#
+
+include $(SRC)/Makefile.master.64
+
+sparcv9_CFLAGS += -xcode=abs44
+
+#
+# XX64
+# work around the problem that gcc currently produces
+# buggy gcc -mcmodel=small code
+#
+amd64_CFLAGS += $(C_PICFLAGS64)
diff --git a/usr/src/ucbcmd/Makefile.ucbtarg b/usr/src/ucbcmd/Makefile.ucbtarg
new file mode 100644
index 0000000000..2b7d43fa97
--- /dev/null
+++ b/usr/src/ucbcmd/Makefile.ucbtarg
@@ -0,0 +1,38 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1990 by Sun Microsystems, Inc.
+#
+# ucbcmd/Makefile.ucbtarg
+#
+# included to define local library targets
+#
+
+# include global targets; SRC should be defined in the shell.
+# SRC is needed until RFE 1026993 is implemented.
+include $(SRC)/cmd/Makefile.targ
+
+# install rules
+$(ROOTBIN):
+ $(INS.dir)
diff --git a/usr/src/ucbcmd/basename/Makefile b/usr/src/ucbcmd/basename/Makefile
new file mode 100644
index 0000000000..b364c97a47
--- /dev/null
+++ b/usr/src/ucbcmd/basename/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= basename
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/basename/basename.c b/usr/src/ucbcmd/basename/basename.c
new file mode 100644
index 0000000000..7a337dee54
--- /dev/null
+++ b/usr/src/ucbcmd/basename/basename.c
@@ -0,0 +1,48 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+#include <stdio.h>
+
+main(argc, argv)
+char **argv;
+{
+ register char *p1, *p2, *p3;
+
+ if (argc < 2) {
+ (void)putchar('\n');
+ exit(1);
+ }
+ p1 = argv[1];
+ p2 = p1;
+ while (*p1) {
+ if (*p1++ == '/')
+ p2 = p1;
+ }
+ if (argc>2) {
+ for(p3=argv[2]; *p3; p3++)
+ ;
+ while(p3>argv[2])
+ if(p1 <= p2 || *--p3 != *--p1)
+ goto output;
+ *p1 = '\0';
+ }
+output:
+ fputs(p2, stdout);
+ putc('\n', stdout);
+ exit(0);
+ /* NOTREACHED */
+}
diff --git a/usr/src/ucbcmd/biff/Makefile b/usr/src/ucbcmd/biff/Makefile
new file mode 100644
index 0000000000..1fdf222478
--- /dev/null
+++ b/usr/src/ucbcmd/biff/Makefile
@@ -0,0 +1,42 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0
+#
+
+PROG= biff
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/biff/biff.c b/usr/src/ucbcmd/biff/biff.c
new file mode 100644
index 0000000000..73d2386af0
--- /dev/null
+++ b/usr/src/ucbcmd/biff/biff.c
@@ -0,0 +1,94 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * biff
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <locale.h>
+
+char *ttyname();
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ char *cp = ttyname(2);
+ struct stat stb;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ argc--, argv++;
+ if (cp == 0)
+ fprintf(stderr, gettext("biff failed: cannot locate your tty: ttyname() for file descriptor 2 returned NULL\n")), exit(1);
+ if (stat(cp, &stb) < 0)
+ perror(cp), exit(1);
+ if (argc == 0) {
+ printf("is %s\n", stb.st_mode&0100 ? gettext("y") : gettext("n"));
+ exit((stb.st_mode&0100) ? 0 : 1);
+ }
+ switch (argv[0][0]) {
+
+ case 'y':
+ if (chmod(cp, stb.st_mode|0100) < 0)
+ perror(cp);
+ break;
+
+ case 'n':
+ if (chmod(cp, stb.st_mode&~0100) < 0)
+ perror(cp);
+ break;
+
+ default:
+ fprintf(stderr, gettext("usage: biff [y] [n]\n"));
+ }
+ exit((stb.st_mode&0100) ? 0 : 1);
+ /* NOTREACHED */
+}
+
diff --git a/usr/src/ucbcmd/cc/Makefile b/usr/src/ucbcmd/cc/Makefile
new file mode 100644
index 0000000000..44a104f093
--- /dev/null
+++ b/usr/src/ucbcmd/cc/Makefile
@@ -0,0 +1,45 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+SHFILES= cc
+CLOBBERFILES= $(SHFILES)
+
+SHSRCS= $(SHFILES:%=%.sh)
+
+include ../Makefile.ucbcmd
+
+.KEEP_STATE:
+
+all: $(SHFILES)
+
+install: all $(ROOTBIN) $(ROOTSHFILES)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/cc/cc.sh b/usr/src/ucbcmd/cc/cc.sh
new file mode 100644
index 0000000000..bf7dd99985
--- /dev/null
+++ b/usr/src/ucbcmd/cc/cc.sh
@@ -0,0 +1,141 @@
+#!/usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1995 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+# All Rights Reserved
+
+#
+# University Copyright- Copyright (c) 1982, 1986, 1988
+# The Regents of the University of California
+# All Rights Reserved
+#
+# University Acknowledgment- Portions of this document are derived from
+# software developed by the University of California, Berkeley, and its
+# contributors.
+#
+
+#ident "%Z%%M% %I% %E% SMI"
+
+# cc command for BSD compatibility package:
+#
+# BSD compatibility package header files (/usr/ucbinclude)
+# are included before SVr4 default (/usr/include) files but
+# after any directories specified on the command line via
+# the -I option. Thus, the BSD header files are included
+# next to last, and SVr4 header files are searched last.
+#
+# BSD compatibility package libraries (/usr/ucblib) are
+# searched next to third to last. SVr4 default libraries
+# (/usr/ccs/lib and /usr/lib) are searched next to last
+#
+# Because the BSD compatibility package C library does not
+# contain all the C library routines of /usr/ccs/lib/libc.a,
+# the BSD package C library is named /usr/ucblib/libucb.a
+# and is passed explicitly to cc. This ensures that libucb.a
+# will be searched first for routines and that
+# /usr/ccs/lib/libc.a will be searched afterwards for routines
+# not found in /usr/ucblib/libucb.a. Also because sockets is
+# provided in libc under BSD, /usr/lib/libsocket and /usr/lib/nsl
+# are also included as default libraries.
+#
+# NOTE: the -Y L, and -Y U, options of cc are not valid
+
+if [ -f /usr/ccs/bin/ucbcc ]
+then
+
+ if [ $# -eq 0 ]
+ then
+ # use this to get the usage message from /usr/ccs/bin/ucbcc
+ /usr/ccs/bin/ucbcc
+ ret=$?
+ exit $ret
+ fi
+
+
+ UCB_LIB_DIR=/usr/ucblib
+ CCS_LIB_DIR=/usr/ccs/lib
+ USR_LIB=/usr/lib
+ TYPE=
+ dopt=
+ cgdir=
+
+ for i in $*
+ do
+ case $i in
+ -cg*)
+ cgdir=`echo $i | sed -n 's/-//p'`
+ ;;
+ -Bstatic|-Bdynamic)
+ dopt=$i
+ ;;
+ -xarch=v9)
+ TYPE=/sparcv9
+ ;;
+ esac
+ done
+
+ if [ x$LD_RUN_PATH = x ]
+ then
+ LD_RUN_PATH=$UCB_LIB_DIR$TYPE
+ else
+ LD_RUN_PATH=$LD_RUN_PATH:$UCB_LIB_DIR$TYPE
+ fi
+ export LD_RUN_PATH
+
+ if [ "$dopt" = "-Bstatic" ]
+ then
+ LIBS="-lucb -lsocket -lnsl -lelf"
+ else
+ LIBS="-lucb -lsocket -lnsl -lelf -laio"
+ fi
+
+ # get the directory where ucbcc points to and set the LD_LIBRARY_PATH
+ # to that directory so as to get the necessary libraries.
+ cclink=`/usr/bin/ls -ln /usr/ccs/bin/ucbcc | awk '{print $11}'`
+ ccdir=`/usr/bin/dirname $cclink`
+ if [ "$cgdir" != "" ]
+ then
+ # can not have cgdir set and compile in 64bit mode, so
+ # reset variables back to 32bit mode
+ TYPE=
+ nccdir="$ccdir/../lib/$cgdir:$ccdir/../lib:$ccdir/$cgdir:$ccdir"
+ else
+ nccdir="$ccdir/../lib$TYPE:$ccdir$TYPE"
+ fi
+
+ LD_LIBRARY_PATH=$UCB_LIB_DIR$TYPE:$CCS_LIB_DIR$TYPE:$USR_LIB$TYPE
+ export LD_LIBRARY_PATH
+
+ /usr/ccs/bin/ucbcc -Xs \
+ -YP,:$UCB_LIB_DIR$TYPE:$nccdir:$CCS_LIB_DIR$TYPE:$USR_LIB$TYPE \
+ "$@" -I/usr/ucbinclude $LIBS
+ ret=$?
+ exit $ret
+else
+ echo "/usr/ucb/cc: language optional software package not installed"
+ exit 1
+fi
diff --git a/usr/src/ucbcmd/chown/Makefile b/usr/src/ucbcmd/chown/Makefile
new file mode 100644
index 0000000000..9317d63e8a
--- /dev/null
+++ b/usr/src/ucbcmd/chown/Makefile
@@ -0,0 +1,47 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989,1996 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+
+PROG= chown
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/chown/chown.c b/usr/src/ucbcmd/chown/chown.c
new file mode 100644
index 0000000000..6d8e102968
--- /dev/null
+++ b/usr/src/ucbcmd/chown/chown.c
@@ -0,0 +1,244 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * chown [-fR] uid[.gid] file ...
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <pwd.h>
+#include <dirent.h>
+#include <grp.h>
+#include <errno.h>
+
+struct passwd *pwd;
+struct passwd *getpwnam();
+struct stat stbuf;
+uid_t uid;
+int status;
+int fflag;
+int rflag;
+
+main(argc, argv)
+ char *argv[];
+{
+ register int c;
+ gid_t gid;
+ register char *cp, *group;
+ struct group *grp;
+ extern char *strchr();
+
+ argc--, argv++;
+ while (argc > 0 && argv[0][0] == '-') {
+ for (cp = &argv[0][1]; *cp; cp++)
+
+ switch (*cp) {
+
+ case 'f':
+ fflag++;
+ break;
+
+ case 'R':
+ rflag++;
+ break;
+
+ default:
+ fatal(255, "unknown option: %c", *cp);
+ }
+ argv++, argc--;
+ }
+ if (argc < 2) {
+ fprintf(stderr, "usage: chown [-fR] owner[.group] file ...\n");
+ exit(-1);
+ }
+ gid = -1;
+ group = strchr(argv[0], '.');
+ if (group != NULL) {
+ *group++ = '\0';
+ if (!isnumber(group)) {
+ if ((grp = getgrnam(group)) == NULL)
+ fatal(255, "unknown group: %s", group);
+ gid = grp -> gr_gid;
+ (void) endgrent();
+ } else if (*group != '\0') {
+ errno = 0;
+ gid = (gid_t)strtol(group, NULL, 10);
+ if (errno != 0) {
+ if (errno == ERANGE) {
+ fatal(2,
+ "group id too large: %s", group);
+ } else {
+ fatal(2, "group id invalid: %s", group);
+ }
+ }
+ }
+ }
+ if (!isnumber(argv[0])) {
+ if ((pwd = getpwnam(argv[0])) == NULL)
+ fatal(255, "unknown user id: %s", argv[0]);
+ uid = pwd->pw_uid;
+ } else {
+ errno = 0;
+ uid = (uid_t)strtol(argv[0], NULL, 10);
+ if (errno != 0) {
+ if (errno == ERANGE) {
+ fatal(2, "user id too large: %s", argv[0]);
+ } else {
+ fatal(2, "user id invalid: %s", argv[0]);
+ }
+ }
+ }
+ for (c = 1; c < argc; c++) {
+ /* do stat for directory arguments */
+ if (lstat(argv[c], &stbuf) < 0) {
+ status += Perror(argv[c]);
+ continue;
+ }
+ if (rflag && ((stbuf.st_mode&S_IFMT) == S_IFDIR)) {
+ status += chownr(argv[c], uid, gid);
+ continue;
+ }
+ if (lchown(argv[c], uid, gid)) {
+ status += Perror(argv[c]);
+ continue;
+ }
+ }
+ exit(status);
+}
+
+isnumber(s)
+ char *s;
+{
+ register c;
+
+ while (c = *s++)
+ if (!isdigit(c))
+ return (0);
+ return (1);
+}
+
+chownr(dir, uid, gid)
+ char *dir;
+ uid_t uid;
+ gid_t gid;
+{
+ register DIR *dirp;
+ register struct dirent *dp;
+ struct stat st;
+ char savedir[1024];
+ int ecode;
+
+ if (getcwd(savedir, 1024) == NULL)
+ fatal(255, "%s", savedir);
+ /*
+ * Change what we are given before doing it's contents.
+ */
+ if (chown(dir, uid, gid) < 0 && Perror(dir))
+ return (1);
+ if (chdir(dir) < 0) {
+ Perror(dir);
+ return (1);
+ }
+ if ((dirp = opendir(".")) == NULL) {
+ Perror(dir);
+ return (1);
+ }
+ dp = readdir(dirp);
+ dp = readdir(dirp); /* read "." and ".." */
+ ecode = 0;
+ for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
+ if (lstat(dp->d_name, &st) < 0) {
+ ecode = Perror(dp->d_name);
+ if (ecode)
+ break;
+ continue;
+ }
+ if ((st.st_mode&S_IFMT) == S_IFDIR) {
+ ecode = chownr(dp->d_name, uid, gid);
+ if (ecode)
+ break;
+ continue;
+ }
+ if (lchown(dp->d_name, uid, gid) < 0 &&
+ (ecode = Perror(dp->d_name)))
+ break;
+ }
+ closedir(dirp);
+ if (chdir(savedir) < 0)
+ fatal(255, "can't change back to %s", savedir);
+ return (ecode);
+}
+
+error(fmt, a)
+ char *fmt, *a;
+{
+
+ if (!fflag) {
+ fprintf(stderr, "chown: ");
+ fprintf(stderr, fmt, a);
+ putc('\n', stderr);
+ }
+ return (!fflag);
+}
+
+fatal(status, fmt, a)
+ int status;
+ char *fmt, *a;
+{
+
+ fflag = 0;
+ (void) error(fmt, a);
+ exit(status);
+}
+
+Perror(s)
+ char *s;
+{
+
+ if (!fflag) {
+ fprintf(stderr, "chown: ");
+ perror(s);
+ }
+ return (!fflag);
+}
diff --git a/usr/src/ucbcmd/df/Makefile b/usr/src/ucbcmd/df/Makefile
new file mode 100644
index 0000000000..84ca9221c4
--- /dev/null
+++ b/usr/src/ucbcmd/df/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= df
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/df/df.sh b/usr/src/ucbcmd/df/df.sh
new file mode 100644
index 0000000000..82a57fdffe
--- /dev/null
+++ b/usr/src/ucbcmd/df/df.sh
@@ -0,0 +1,74 @@
+#!/usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1991 by Sun Microsystems, Inc.
+#
+#
+# Replace /usr/ucb/df
+#
+
+ARG=-k
+count=1
+num=$#
+
+if [ $# -lt 1 ]
+then
+ /usr/sbin/df $ARG
+ exit $?
+fi
+
+while [ "$count" -le "$num" ]
+do
+ flag=$1
+ case $flag in
+ '-a')
+ ARG="$ARG -a"
+ ;;
+ '-t')
+ ARG="$ARG -F"
+ shift
+ if [ "$1" = "4.2" ]
+ then
+ ARG="$ARG ufs"
+ else
+ ARG="$ARG $1"
+ fi
+ count=`expr $count + 1`
+ ;;
+ '-i')
+ ARG="$ARG -F ufs -o i"
+ ;;
+ *)
+ ARG="$ARG $flag"
+ ;;
+ esac
+ if [ "$count" -lt "$num" ]
+ then
+ shift
+ fi
+ count=`expr $count + 1`
+done
+/usr/sbin/df $ARG
+exit $?
diff --git a/usr/src/ucbcmd/du/Makefile b/usr/src/ucbcmd/du/Makefile
new file mode 100644
index 0000000000..c90380447e
--- /dev/null
+++ b/usr/src/ucbcmd/du/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= du
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/du/du.sh b/usr/src/ucbcmd/du/du.sh
new file mode 100644
index 0000000000..7aaa0c21fb
--- /dev/null
+++ b/usr/src/ucbcmd/du/du.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1991 by Sun Microsystems, Inc.
+#
+#
+# Replace /usr/ucb/du
+#
+
+exec /usr/bin/du -kr "$@"
diff --git a/usr/src/ucbcmd/echo/Makefile b/usr/src/ucbcmd/echo/Makefile
new file mode 100644
index 0000000000..ccfdb759a0
--- /dev/null
+++ b/usr/src/ucbcmd/echo/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= echo
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/echo/echo.c b/usr/src/ucbcmd/echo/echo.c
new file mode 100644
index 0000000000..ba5a83344d
--- /dev/null
+++ b/usr/src/ucbcmd/echo/echo.c
@@ -0,0 +1,43 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * echo
+ */
+#include <stdio.h>
+
+main(argc, argv)
+int argc;
+char *argv[];
+{
+ register int i, nflg;
+
+ nflg = 0;
+ if(argc > 1 && argv[1][0] == '-' && argv[1][1] == 'n' && !argv[1][2]) {
+ nflg++;
+ argc--;
+ argv++;
+ }
+ for(i=1; i<argc; i++) {
+ fputs(argv[i], stdout);
+ if (i < argc-1)
+ putchar(' ');
+ }
+ if(nflg == 0)
+ putchar('\n');
+ exit(0);
+}
diff --git a/usr/src/ucbcmd/expr/Makefile b/usr/src/ucbcmd/expr/Makefile
new file mode 100644
index 0000000000..4db98c4b7d
--- /dev/null
+++ b/usr/src/ucbcmd/expr/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 1991 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+
+PROG= expr
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/expr/expr.y b/usr/src/ucbcmd/expr/expr.y
new file mode 100644
index 0000000000..c18a01ea2e
--- /dev/null
+++ b/usr/src/ucbcmd/expr/expr.y
@@ -0,0 +1,398 @@
+%{
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+%}
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+%{
+#pragma ident "%Z%%M% %I% %E% SMI"
+%}
+
+/* Yacc productions for "expr" command: */
+
+%{
+typedef char *yystype;
+#define YYSTYPE yystype
+%}
+
+%token OR AND ADD SUBT MULT DIV REM EQ GT GEQ LT LEQ NEQ
+%token A_STRING SUBSTR LENGTH INDEX NOARG MATCH
+
+/* operators listed below in increasing precedence: */
+%left OR
+%left AND
+%left EQ LT GT GEQ LEQ NEQ
+%left ADD SUBT
+%left MULT DIV REM
+%left MCH
+%left MATCH
+%left SUBSTR
+%left LENGTH INDEX
+%%
+
+/* a single `expression' is evaluated and printed: */
+
+expression: expr NOARG = {
+ printf("%s\n", $1);
+ exit((!strcmp($1,"0")||!strcmp($1,"\0"))? 1: 0);
+ }
+ ;
+
+
+expr: '(' expr ')' = { $$ = $2; }
+ | expr OR expr = { $$ = conj(OR, $1, $3); }
+ | expr AND expr = { $$ = conj(AND, $1, $3); }
+ | expr EQ expr = { $$ = rel(EQ, $1, $3); }
+ | expr GT expr = { $$ = rel(GT, $1, $3); }
+ | expr GEQ expr = { $$ = rel(GEQ, $1, $3); }
+ | expr LT expr = { $$ = rel(LT, $1, $3); }
+ | expr LEQ expr = { $$ = rel(LEQ, $1, $3); }
+ | expr NEQ expr = { $$ = rel(NEQ, $1, $3); }
+ | expr ADD expr = { $$ = arith(ADD, $1, $3); }
+ | expr SUBT expr = { $$ = arith(SUBT, $1, $3); }
+ | expr MULT expr = { $$ = arith(MULT, $1, $3); }
+ | expr DIV expr = { $$ = arith(DIV, $1, $3); }
+ | expr REM expr = { $$ = arith(REM, $1, $3); }
+ | expr MCH expr = { $$ = match($1, $3); }
+ | MATCH expr expr = { $$ = match($2, $3); }
+ | SUBSTR expr expr expr = { $$ = substr($2, $3, $4); }
+ | LENGTH expr = { $$ = length($2); }
+ | INDEX expr expr = { $$ = index($2, $3); }
+ | A_STRING
+ ;
+%%
+
+#define ESIZE 256
+#define EQL(x,y) !strcmp(x,y)
+
+#define INIT register char *sp = instring;
+#define GETC() (*sp++)
+#define PEEKC() (*sp)
+#define UNGETC(c) (--sp)
+#define RETURN(c) return
+#define ERROR(c) errxx(c)
+#include <regexp.h>
+#include <malloc.h>
+
+long atol();
+char *ltoa(), *strcpy(), *strncpy();
+void exit();
+char **Av;
+int Ac;
+int Argi;
+
+char Mstring[1][128];
+
+
+char *operator[] = {
+ "|", "&", "+", "-", "*", "/", "%", ":",
+ "=", "==", "<", "<=", ">", ">=", "!=",
+ "match", "substr", "length", "index", "\0" };
+int op[] = {
+ OR, AND, ADD, SUBT, MULT, DIV, REM, MCH,
+ EQ, EQ, LT, LEQ, GT, GEQ, NEQ,
+ MATCH, SUBSTR, LENGTH, INDEX };
+yylex() {
+ register char *p;
+ register i;
+
+ if(Argi >= Ac) return NOARG;
+
+ p = Av[Argi++];
+
+ if((*p == '(' || *p == ')') && p[1] == '\0' )
+ return (int)*p;
+ for(i = 0; *operator[i]; ++i)
+ if(EQL(operator[i], p))
+ return op[i];
+
+ yylval = p;
+ return A_STRING;
+}
+
+char *rel(oper, r1, r2) register char *r1, *r2;
+{
+ register long i;
+
+ if(ematch(r1, "-\\{0,1\\}[0-9]*$") && ematch(r2, "-\\{0,1\\}[0-9]*$"))
+ i = atol(r1) - atol(r2);
+ else
+ i = strcmp(r1, r2);
+ switch(oper) {
+ case EQ:
+ i = i==0;
+ break;
+ case GT:
+ i = i>0;
+ break;
+ case GEQ:
+ i = i>=0;
+ break;
+ case LT:
+ i = i<0;
+ break;
+ case LEQ:
+ i = i<=0;
+ break;
+ case NEQ:
+ i = i!=0;
+ break;
+ }
+ return i? "1": "0";
+}
+
+char *arith(oper, r1, r2) char *r1, *r2;
+{
+ long i1, i2;
+ register char *rv;
+
+ if(!(ematch(r1, "-\\{0,1\\}[0-9]*$") && ematch(r2, "-\\{0,1\\}[0-9]*$")))
+ yyerror("non-numeric argument");
+ i1 = atol(r1);
+ i2 = atol(r2);
+
+ switch(oper) {
+ case ADD:
+ i1 = i1 + i2;
+ break;
+ case SUBT:
+ i1 = i1 - i2;
+ break;
+ case MULT:
+ i1 = i1 * i2;
+ break;
+ case DIV:
+ if (i2 == 0)
+ yyerror("division by zero");
+ i1 = i1 / i2;
+ break;
+ case REM:
+ if (i2 == 0)
+ yyerror("division by zero");
+ i1 = i1 % i2;
+ break;
+ }
+ rv = malloc(16);
+ (void) strcpy(rv, ltoa(i1));
+ return rv;
+}
+char *conj(oper, r1, r2) char *r1, *r2;
+{
+ register char *rv;
+
+ switch(oper) {
+
+ case OR:
+ if(EQL(r1, "0")
+ || EQL(r1, ""))
+ if(EQL(r2, "0")
+ || EQL(r2, ""))
+ rv = "0";
+ else
+ rv = r2;
+ else
+ rv = r1;
+ break;
+ case AND:
+ if(EQL(r1, "0")
+ || EQL(r1, ""))
+ rv = "0";
+ else if(EQL(r2, "0")
+ || EQL(r2, ""))
+ rv = "0";
+ else
+ rv = r1;
+ break;
+ }
+ return rv;
+}
+
+char *substr(v, s, w) char *v, *s, *w; {
+register si, wi;
+register char *res;
+
+ si = atol(s);
+ wi = atol(w);
+ while(--si) if(*v) ++v;
+
+ res = v;
+
+ while(wi--) if(*v) ++v;
+
+ *v = '\0';
+ return res;
+}
+
+char *index(s, t) char *s, *t; {
+ register long i, j;
+ register char *rv;
+
+ for(i = 0; s[i] ; ++i)
+ for(j = 0; t[j] ; ++j)
+ if(s[i]==t[j]) {
+ (void) strcpy(rv = malloc(8), ltoa(++i));
+ return rv;
+ }
+ return "0";
+}
+
+char *length(s) register char *s; {
+ register long i = 0;
+ register char *rv;
+
+ while(*s++) ++i;
+
+ rv = malloc(8);
+ (void) strcpy(rv, ltoa(i));
+ return rv;
+}
+
+char *match(s, p)
+char *s, *p;
+{
+ register char *rv;
+
+ (void) strcpy(rv=malloc(8), ltoa((long)ematch(s, p)));
+ if(nbra) {
+ rv = malloc((unsigned) strlen(Mstring[0]) + 1);
+ (void) strcpy(rv, Mstring[0]);
+ }
+ return rv;
+}
+
+ematch(s, p)
+char *s;
+register char *p;
+{
+ static char expbuf[ESIZE];
+ char *compile();
+ register num;
+ extern char *braslist[], *braelist[], *loc2;
+
+ compile(p, expbuf, &expbuf[ESIZE], 0);
+ if(nbra > 1)
+ yyerror("Too many '\\('s");
+ if(advance(s, expbuf)) {
+ if(nbra == 1) {
+ p = braslist[0];
+ num = braelist[0] - p;
+ if ((num > 127) || (num < 0)) yyerror("Paren problem");
+ (void) strncpy(Mstring[0], p, num);
+ Mstring[0][num] = '\0';
+ }
+ return(loc2-s);
+ }
+ return(0);
+}
+
+errxx(err)
+register err;
+{
+ register char *message;
+
+ switch(err) {
+ case 11:
+ message = "Range endpoint too large";
+ break;
+ case 16:
+ message = "Bad number";
+ break;
+ case 25:
+ message = "``\\digit'' out of range";
+ break;
+ case 36:
+ message = "Illegal or missing delimiter";
+ break;
+ case 41:
+ message = "No remembered search string";
+ break;
+ case 42:
+ message = "\\( \\) imbalance";
+ break;
+ case 43:
+ message = "Too many \\(";
+ break;
+ case 44:
+ message = "More than 2 numbers given in \\{ \\}";
+ break;
+ case 45:
+ message = "} expected after \\";
+ break;
+ case 46:
+ message = "First number exceeds second in \\{ \\}";
+ break;
+ case 49:
+ message = "[ ] imbalance";
+ break;
+ case 50:
+ message = "Regular expression too long";
+ break;
+ default:
+ message = "Unknown regexp error code!!";
+ break;
+ }
+ yyerror(message);
+}
+
+yyerror(s)
+char *s;
+{
+ (void) write(2, "expr: ", 6);
+ (void) write(2, s, (unsigned) strlen(s));
+ (void) write(2, "\n", 1);
+ exit(2);
+}
+
+char *ltoa(l)
+long l;
+{
+ static char str[20];
+ register char *sp;
+ register i;
+ register neg;
+
+ if(l == 0x80000000L)
+ return "-2147483648";
+ neg = 0;
+ if(l < 0)
+ ++neg, l = -l;
+ sp = &str[20];
+ *--sp = '\0';
+ do {
+ i = l % 10;
+ *--sp = '0' + i;
+ l /= 10;
+ }
+ while(l);
+ if(neg)
+ *--sp = '-';
+ return sp;
+}
+
+main(argc, argv) char **argv;
+{
+ Ac = argc;
+ Argi = 1;
+ Av = argv;
+ yyparse();
+}
diff --git a/usr/src/ucbcmd/fastboot/Makefile b/usr/src/ucbcmd/fastboot/Makefile
new file mode 100644
index 0000000000..57f445d833
--- /dev/null
+++ b/usr/src/ucbcmd/fastboot/Makefile
@@ -0,0 +1,50 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+SHFILES= fastboot
+CLOBBERFILES= $(SHFILES)
+
+SHSRCS= $(SHFILES:%=%.sh)
+
+include ../Makefile.ucbcmd
+
+.KEEP_STATE:
+
+all: $(SHFILES)
+
+%: %.sh
+ $(RM) $@
+ $(CP) $< $@
+
+install: all $(ROOTBIN) $(ROOTSHFILES)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/fastboot/fastboot.sh b/usr/src/ucbcmd/fastboot/fastboot.sh
new file mode 100644
index 0000000000..d23ec9e17a
--- /dev/null
+++ b/usr/src/ucbcmd/fastboot/fastboot.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1989 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+# All Rights Reserved
+
+#
+# University Copyright- Copyright (c) 1982, 1986, 1988
+# The Regents of the University of California
+# All Rights Reserved
+#
+# University Acknowledgment- Portions of this document are derived from
+# software developed by the University of California, Berkeley, and its
+# contributors.
+#
+
+#ident "%Z%%M% %I% %E% SMI"
+
+PATH=/usr/sbin:/bin:/usr/bin:/usr/etc:$PATH
+export PATH
+uadmin 2 1
diff --git a/usr/src/ucbcmd/fasthalt/Makefile b/usr/src/ucbcmd/fasthalt/Makefile
new file mode 100644
index 0000000000..9a46eec721
--- /dev/null
+++ b/usr/src/ucbcmd/fasthalt/Makefile
@@ -0,0 +1,50 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+SHFILES= fasthalt
+CLOBBERFILES= $(SHFILES)
+
+SHSRCS= $(SHFILES:%=%.sh)
+
+include ../Makefile.ucbcmd
+
+.KEEP_STATE:
+
+all: $(SHFILES)
+
+%: %.sh
+ $(RM) $@
+ $(CP) $< $@
+
+install: all $(ROOTBIN) $(ROOTSHFILES)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/fasthalt/fasthalt.sh b/usr/src/ucbcmd/fasthalt/fasthalt.sh
new file mode 100644
index 0000000000..5f9b28714d
--- /dev/null
+++ b/usr/src/ucbcmd/fasthalt/fasthalt.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1989 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+# All Rights Reserved
+
+#
+# University Copyright- Copyright (c) 1982, 1986, 1988
+# The Regents of the University of California
+# All Rights Reserved
+#
+# University Acknowledgment- Portions of this document are derived from
+# software developed by the University of California, Berkeley, and its
+# contributors.
+#
+
+#ident "%Z%%M% %I% %E% SMI"
+
+PATH=/usr/sbin:/bin:/usr/bin:/usr/etc:$PATH
+export PATH
+halt $*
diff --git a/usr/src/ucbcmd/file/Makefile b/usr/src/ucbcmd/file/Makefile
new file mode 100644
index 0000000000..520b71a2ca
--- /dev/null
+++ b/usr/src/ucbcmd/file/Makefile
@@ -0,0 +1,49 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+SHFILES= file
+CLOBBERFILES= $(SHFILES)
+
+SHSRCS= $(SHFILES:%=%.sh)
+
+include ../Makefile.ucbcmd
+
+.KEEP_STATE:
+
+all: $(SHFILES)
+
+%: %.sh
+ $(RM) $@
+ $(CP) $< $@
+
+install: all $(ROOTBIN) $(ROOTSHFILES)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/file/file.sh b/usr/src/ucbcmd/file/file.sh
new file mode 100644
index 0000000000..2618c05819
--- /dev/null
+++ b/usr/src/ucbcmd/file/file.sh
@@ -0,0 +1,51 @@
+#! /usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#ident "%Z%%M% %I% %E% SMI"
+
+#
+# Copyright (c) 1991 by Sun Microsystems, Inc.
+#
+
+# This script invokes /usr/bin/file with -h option by default and
+# turns off -h when passed with -L option.
+
+CFLAG=
+FFLAG=
+MFLAG=
+HFLAG=-h
+USAGE="usage: file [-cL] [-f ffile] [-m mfile] file..."
+
+while getopts cLf:m: opt
+do
+ case $opt in
+ c) CFLAG=-$opt;;
+ L) HFLAG= ;;
+ m) MFLAG=-$opt; MARG=$OPTARG;;
+ f) FFLAG=-$opt; FARG=$OPTARG;;
+ \?) echo $USAGE;
+ exit 1;;
+ esac
+done
+shift `expr $OPTIND - 1`
+/usr/bin/file $HFLAG $CFLAG $MFLAG $MARG $FFLAG $FARG $*
diff --git a/usr/src/ucbcmd/from/Makefile b/usr/src/ucbcmd/from/Makefile
new file mode 100644
index 0000000000..1aff6fc3bf
--- /dev/null
+++ b/usr/src/ucbcmd/from/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1990 by Sun Microsystems, Inc.
+#
+
+PROG= from
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/from/from.c b/usr/src/ucbcmd/from/from.c
new file mode 100644
index 0000000000..7929d036ad
--- /dev/null
+++ b/usr/src/ucbcmd/from/from.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright 1994 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <pwd.h>
+#include <sys/param.h>
+#include <string.h>
+
+static int match(char *, char *);
+
+main(argc, argv)
+ int argc;
+ register char **argv;
+{
+ char lbuf[BUFSIZ];
+ char lbuf2[BUFSIZ];
+ register struct passwd *pp;
+ int stashed = 0;
+ register char *name;
+ char *sender = NULL;
+ char mailbox[MAXPATHLEN];
+ char *tmp_mailbox;
+ extern char *optarg;
+ extern int optind;
+ extern int opterr;
+ int c;
+ int errflg = 0;
+
+ opterr = 0;
+ while ((c = getopt(argc, argv, "s:")) != EOF)
+ switch (c) {
+ case 's':
+ sender = optarg;
+ for (name = sender; *name; name++)
+ if (isupper(*name))
+ *name = tolower(*name);
+ break;
+ case '?':
+ errflg++;
+ break;
+ }
+ if (errflg) {
+ (void) fprintf(stderr,
+ "Usage: from [-s sender] [user]\n");
+ exit(1);
+ }
+
+ if (optind < argc) {
+ (void) sprintf(mailbox, "/var/mail/%s", argv[optind]);
+ } else {
+ if (tmp_mailbox = getenv("MAIL")) {
+ (void) strcpy(mailbox, tmp_mailbox);
+ } else {
+ name = getlogin();
+ if (name == NULL || strlen(name) == 0) {
+ pp = getpwuid(getuid());
+ if (pp == NULL) {
+ (void) fprintf(stderr,
+ "Who are you?\n");
+ exit(1);
+ }
+ name = pp->pw_name;
+ }
+ (void) sprintf(mailbox, "/var/mail/%s", name);
+ }
+ }
+ if (freopen(mailbox, "r", stdin) == NULL) {
+ (void) fprintf(stderr, "Can't open %s\n", mailbox);
+ exit(0);
+ }
+ while (fgets(lbuf, sizeof (lbuf), stdin) != NULL)
+ if (lbuf[0] == '\n' && stashed) {
+ stashed = 0;
+ (void) printf("%s", lbuf2);
+ } else if (strncmp(lbuf, "From ", 5) == 0 &&
+ (sender == NULL || match(&lbuf[4], sender))) {
+ (void) strcpy(lbuf2, lbuf);
+ stashed = 1;
+ }
+ if (stashed)
+ (void) printf("%s", lbuf2);
+ return(0);
+}
+
+static int
+match(line, str)
+ register char *line, *str;
+{
+ register char ch;
+
+ while (*line == ' ' || *line == '\t')
+ ++line;
+ if (*line == '\n')
+ return (0);
+ while (*str && *line != ' ' && *line != '\t' && *line != '\n') {
+ ch = isupper(*line) ? tolower(*line) : *line;
+ if (ch != *str++)
+ return (0);
+ line++;
+ }
+ return (*str == '\0');
+}
diff --git a/usr/src/ucbcmd/groups/Makefile b/usr/src/ucbcmd/groups/Makefile
new file mode 100644
index 0000000000..fddf23ae6f
--- /dev/null
+++ b/usr/src/ucbcmd/groups/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= groups
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/groups/groups.c b/usr/src/ucbcmd/groups/groups.c
new file mode 100644
index 0000000000..976430696c
--- /dev/null
+++ b/usr/src/ucbcmd/groups/groups.c
@@ -0,0 +1,101 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * groups
+ */
+
+#include <sys/param.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+
+int groups[NGROUPS_UMAX];
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ int ngroups, i, j;
+ char *sep = "";
+ register struct group *gr;
+ struct passwd *pw;
+
+ if (argc > 1) {
+ for (i=1; i < argc ; i++)
+ showgroups(argv[i]);
+ exit(0) ;
+ }
+
+ ngroups = getgroups(NGROUPS_UMAX, groups);
+ if ((pw = getpwuid(getuid())) == NULL) {
+ fprintf(stderr, "groups: could not find passwd entry\n");
+ exit(1);
+ }
+
+ for (i = 0; i < ngroups; i++) {
+ gr = getgrgid(groups[i]);
+ if (gr == NULL) {
+ printf("%s%d", sep, groups[i]);
+ sep = " ";
+ continue;
+ }
+ printf("%s%s", sep, gr->gr_name);
+ sep = " ";
+ }
+ printf("\n");
+ exit(0);
+ /* NOTREACHED */
+}
+
+showgroups(user)
+ register char *user;
+{
+ register struct group *gr;
+ register struct passwd *pw;
+ register char **cp;
+ char *sep = "";
+ int pwgid_printed = 0 ;
+
+ if ((pw = getpwnam(user)) == NULL) {
+ fprintf(stderr, "groups: %s : No such user\n", user);
+ return;
+ }
+ setgrent() ;
+ printf("%s : ", user) ;
+ while (gr = getgrent()) {
+ if (pw->pw_gid == gr->gr_gid) {
+ /*
+ * To avoid duplicate group entries
+ */
+ if (pwgid_printed==0) {
+ printf("%s%s", sep, gr->gr_name);
+ sep = " ";
+ pwgid_printed = 1 ;
+ }
+ continue ;
+ }
+ for (cp = gr->gr_mem; cp && *cp; cp++)
+ if (strcmp(*cp, user) == 0) {
+ printf("%s%s", sep, gr->gr_name);
+ sep = " ";
+ break;
+ }
+ }
+ printf("\n");
+ endgrent() ;
+}
diff --git a/usr/src/ucbcmd/install.d/Makefile b/usr/src/ucbcmd/install.d/Makefile
new file mode 100644
index 0000000000..b674fc0a22
--- /dev/null
+++ b/usr/src/ucbcmd/install.d/Makefile
@@ -0,0 +1,62 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989,1996 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+
+PROG= installcmd
+
+PROG2= install
+
+PROGSRC= install.c
+
+include ../Makefile.ucbcmd
+
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+
+FILEMODE= 755
+
+# for messaging catalog
+#
+POFILE= install.po
+
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(PROGSRC)
+ $(LINK.c) $(PROGSRC) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG)
+ rm -f $(ROOTBIN)/$(PROG2)
+ mv $(ROOTBIN)/$(PROG) $(ROOTBIN)/$(PROG2)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/install.d/install.c b/usr/src/ucbcmd/install.d/install.c
new file mode 100644
index 0000000000..f0ec328457
--- /dev/null
+++ b/usr/src/ucbcmd/install.d/install.c
@@ -0,0 +1,354 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1996 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <locale.h>
+
+#define DEF_GROUP "staff" /* default group */
+#define DEF_OWNER "root" /* default owner */
+#define DEF_MODE 0755 /* default mode */
+
+char *group = DEF_GROUP;
+char *owner = DEF_OWNER;
+int mode = DEF_MODE;
+int sflag = 0;
+struct passwd *pp;
+struct group *gp;
+extern int errno;
+int copy();
+void usage();
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ extern char *optarg;
+ extern int optind;
+ struct stat stb;
+ char *dirname;
+ int ch;
+ int i;
+ int rc;
+ int dflag = 0;
+ int gflag = 0;
+ int oflag = 0;
+ int mflag = 0;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ while ((ch = getopt(argc, argv, "dcg:o:m:s")) != EOF)
+ switch((char)ch) {
+ case 'c':
+ break; /* always do "copy" */
+ case 'd':
+ dflag++;
+ break;
+ case 'g':
+ gflag++;
+ group = optarg;
+ break;
+ case 'm':
+ mflag++;
+ mode = atoo(optarg);
+ break;
+ case 'o':
+ oflag++;
+ owner = optarg;
+ break;
+ case 's':
+ sflag++;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ argc -= optind;
+ argv += optind;
+
+ /* get group and owner id's */
+ if (!(gp = getgrnam(group))) {
+ fprintf(stderr, gettext("install: unknown group %s.\n"), group);
+ exit(1);
+ }
+ if (!(pp = getpwnam(owner))) {
+ fprintf(stderr, gettext("install: unknown user %s.\n"), owner);
+ exit(1);
+ }
+
+ if (dflag) { /* install a directory */
+ int exists = 0;
+
+ if (argc != 1)
+ usage();
+ dirname = argv[0];
+ if (mkdirp(dirname, 0777) < 0) {
+ exists = errno == EEXIST;
+ if (!exists) {
+ fprintf(stderr, gettext("install: mkdir: %s: %s\n"), dirname, strerror(errno));
+ exit(1);
+ }
+ }
+ if (stat(dirname, &stb) < 0) {
+ fprintf(stderr, gettext("install: stat: %s: %s\n"), dirname, strerror(errno));
+ exit(1);
+ }
+ if ((stb.st_mode&S_IFMT) != S_IFDIR) {
+ fprintf(stderr, gettext("install: %s is not a directory\n"), dirname);
+ }
+ /* make sure directory setgid bit is inherited */
+ mode = (mode & ~S_ISGID) | (stb.st_mode & S_ISGID);
+ if (mflag && chmod(dirname, mode)) {
+ fprintf(stderr, gettext("install: chmod: %s: %s\n"), dirname, strerror(errno));
+ if (!exists)
+ (void) unlink(dirname);
+ exit(1) ;
+ }
+ if (oflag && chown(dirname, pp->pw_uid, -1) && errno != EPERM) {
+ fprintf(stderr, gettext("install: chown: %s: %s\n"), dirname, strerror(errno));
+ if (!exists)
+ (void) unlink(dirname);
+ exit(1) ;
+ }
+ if (gflag && chown(dirname, -1, gp->gr_gid) && errno != EPERM) {
+ fprintf(stderr, gettext("install: chgrp: %s: %s\n"), dirname, strerror(errno));
+ if (!exists)
+ (void) unlink(dirname);
+ exit(1) ;
+ }
+ exit(0);
+ }
+
+ if (argc < 2)
+ usage();
+
+ if (argc > 2) { /* last arg must be a directory */
+ if (stat(argv[argc-1], &stb) < 0)
+ usage();
+ if ((stb.st_mode&S_IFMT) != S_IFDIR)
+ usage();
+ }
+ rc = 0;
+ for (i = 0; i < argc-1; i++)
+ rc |= install(argv[i], argv[argc-1]);
+ exit(rc);
+ /* NOTREACHED */
+}
+
+int
+install(from, to)
+ char *from, *to;
+{
+ int to_fd;
+ int devnull;
+ int status = 0;
+ char *path;
+ struct stat from_sb, to_sb;
+ static char pbuf[MAXPATHLEN];
+ char buf[MAXPATHLEN + 10];
+
+ /* check source */
+ if (stat(from, &from_sb)) {
+ fprintf(stderr, gettext("install: %s: %s\n"), from, strerror(errno));
+ return (1);
+ }
+ /* special case for removing files */
+ devnull = !strcmp(from, "/dev/null");
+ if (!devnull && !((from_sb.st_mode&S_IFMT) == S_IFREG)) {
+ fprintf(stderr, gettext("install: %s isn't a regular file.\n"), from);
+ return (1);
+ }
+
+ /* build target path, find out if target is same as source */
+ if (!stat(path = to, &to_sb)) {
+ if ((to_sb.st_mode&S_IFMT) == S_IFDIR) {
+ char *C, *strrchr();
+
+ (void) sprintf(path = pbuf, "%s/%s", to, (C = strrchr(from, '/')) ? ++C : from);
+ if (stat(path, &to_sb))
+ goto nocompare;
+ }
+ if ((to_sb.st_mode&S_IFMT) != S_IFREG) {
+ fprintf(stderr, gettext("install: %s isn't a regular file.\n"), path);
+ return (1);
+ }
+ if (to_sb.st_dev == from_sb.st_dev && to_sb.st_ino == from_sb.st_ino) {
+ fprintf(stderr, gettext("install: %s and %s are the same file.\n"), from, path);
+ return (1);
+ }
+ /* unlink now... avoid ETXTBSY errors later */
+ (void) unlink(path);
+ }
+
+nocompare:
+ /* open target, set mode, owner, group */
+ if ((to_fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, 0)) < 0) {
+ fprintf(stderr, gettext("install: %s: %s\n"), path, strerror(errno));
+ return (1);
+ }
+ if (fchmod(to_fd, mode)) {
+ fprintf(stderr, gettext("install: chmod: %s: %s\n"), path, strerror(errno));
+ status = 1;
+ close(to_fd);
+ goto inst_done;
+ }
+ if (!devnull) {
+ status = copy(from, to_fd, path); /* copy */
+ close(to_fd);
+ }
+ if (sflag) {
+ sprintf(buf, "strip %s", path);
+ system(buf);
+ }
+ if (chown(path, pp->pw_uid, gp->gr_gid) && errno != EPERM) {
+ fprintf(stderr, gettext("install: chown: %s: %s\n"), path, strerror(errno));
+ status = 1;
+ }
+
+inst_done:
+ if (status)
+ (void) unlink(path);
+ return (status);
+}
+
+/*
+ * copy --
+ * copy from one file to another
+ */
+int
+copy(from_name, to_fd, to_name)
+ int to_fd;
+ char *from_name, *to_name;
+{
+ int n, from_fd;
+ int status = 0;
+ char buf[MAXBSIZE];
+
+ if ((from_fd = open(from_name, O_RDONLY, 0)) < 0) {
+ fprintf(stderr, gettext("install: open: %s: %s\n"), from_name, strerror(errno));
+ return (1);
+ }
+ while ((n = read(from_fd, buf, sizeof(buf))) > 0)
+ if (write(to_fd, buf, n) != n) {
+ fprintf(stderr, gettext("install: write: %s: %s\n"), to_name, strerror(errno));
+ status = 1;
+ goto copy_done;
+ }
+ if (n == -1) {
+ fprintf(stderr, gettext("install: read: %s: %s\n"), from_name, strerror(errno));
+ status = 1;
+ goto copy_done;
+ }
+
+copy_done:
+ (void) close(from_fd);
+ return (status);
+}
+
+/*
+ * atoo --
+ * octal string to int
+ */
+int
+atoo(str)
+ register char *str;
+{
+ register int val;
+
+ for (val = 0; isdigit(*str); ++str)
+ val = val * 8 + *str - '0';
+ return(val);
+}
+
+
+/*
+ * usage --
+ * print a usage message and die
+ */
+void
+usage()
+{
+ fputs(gettext("usage: install [-cs] [-g group] [-m mode] [-o owner] file ... destination\n"), stderr);
+ fputs(gettext(" install -d [-g group] [-m mode] [-o owner] dir\n"), stderr);
+ exit(1);
+}
+
+/*
+ * mkdirp --
+ * make a directory and parents if needed
+ */
+int
+mkdirp(dir, mode)
+ char *dir;
+ int mode;
+{
+ int err;
+ char *slash;
+ char *strrchr();
+ extern int errno;
+
+ if (mkdir(dir, mode) == 0)
+ return (0);
+ if (errno != ENOENT)
+ return (-1);
+ slash = strrchr(dir, '/');
+ if (slash == NULL)
+ return (-1);
+ *slash = '\0';
+ err = mkdirp(dir, 0777);
+ *slash = '/';
+ if (err)
+ return (err);
+ return mkdir(dir, mode);
+}
diff --git a/usr/src/ucbcmd/ld/Makefile b/usr/src/ucbcmd/ld/Makefile
new file mode 100644
index 0000000000..b4acb80b16
--- /dev/null
+++ b/usr/src/ucbcmd/ld/Makefile
@@ -0,0 +1,49 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+SHFILES= ld
+CLOBBERFILES= $(SHFILES)
+
+SHSRCS= $(SHFILES:%=%.sh)
+
+include ../Makefile.ucbcmd
+
+.KEEP_STATE:
+
+all: $(SHFILES)
+
+%: %.sh
+ $(RM) $@
+ $(CP) $< $@
+
+install: all $(ROOTBIN) $(ROOTSHFILES)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/ld/ld.sh b/usr/src/ucbcmd/ld/ld.sh
new file mode 100644
index 0000000000..ba2296ec45
--- /dev/null
+++ b/usr/src/ucbcmd/ld/ld.sh
@@ -0,0 +1,77 @@
+#!/usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+# All Rights Reserved
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.7 */
+
+# Copyright (c) 1984 AT&T
+# All Rights Reserved
+
+
+# Portions Copyright(c) 1988, Sun Microsystems, Inc.
+# All Rights Reserved
+
+# ld command for BSD compatibility package:
+#
+# BSD compatibility package libraries (/usr/ucblib) are
+# searched next to third to last. SVr4 default libraries
+# (/usr/ccs/lib and /usr/lib) are searched next to last and
+# last respectively.
+#
+# Because the BSD compatibility package C library does not
+# contain all the C library routines of /usr/ccs/lib/libc.a,
+# the BSD package C library is named /usr/ucblib/libucb.a
+# and is passed explicitly to ld. This ensures that libucb.a
+# will be searched first for routines and that
+# /usr/ccs/lib/libc.a will be searched afterwards for routines
+# not found in /usr/ucblib/libucb.a. Also because sockets is
+# provided in libc under BSD, /usr/lib/libsocket and /usr/lib/nsl
+# are also included as default libraries.
+#
+# NOTE: the -Y L, and -Y U, options of ld are not valid
+
+opts=
+LIBS="-lucb -lresolv -lsocket -lnsl -lelf"
+
+if [ $# -eq 0 ]
+then
+ exit 1
+elif [ $# -gt 0 ]
+then
+ for i in $*
+ do
+ case $i in
+ -r)
+ LIBS=""
+ opts="$opts $i"
+ shift;;
+ *)
+ opts="$opts $i"
+ shift;;
+ esac
+ done
+fi
+
+LD_RUN_PATH=/usr/ucblib /usr/ccs/bin/ld -YP,:/usr/ucblib:/usr/ccs/lib:/usr/lib $opts $LIBS
diff --git a/usr/src/ucbcmd/lint.d/Makefile b/usr/src/ucbcmd/lint.d/Makefile
new file mode 100644
index 0000000000..826b297488
--- /dev/null
+++ b/usr/src/ucbcmd/lint.d/Makefile
@@ -0,0 +1,54 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+SHFILES= lintcmd
+
+SHFILES2= lint
+
+CLOBBERFILES= $(SHFILES) $(SHFILES2)
+
+SHSRCS= $(SHFILES2:%=%.sh)
+
+include ../Makefile.ucbcmd
+
+.KEEP_STATE:
+
+all: $(SHFILES)
+
+$(SHFILES): $(SHSRCS)
+ $(RM) $@
+ $(CP) $(SHSRCS) $@
+
+install: all $(ROOTBIN) $(ROOTSHFILES)
+ rm -f $(ROOTBIN)/$(SHFILES2)
+ mv $(ROOTBIN)/$(SHFILES) $(ROOTBIN)/$(SHFILES2)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/lint.d/lint.sh b/usr/src/ucbcmd/lint.d/lint.sh
new file mode 100644
index 0000000000..c265bb3969
--- /dev/null
+++ b/usr/src/ucbcmd/lint.d/lint.sh
@@ -0,0 +1,77 @@
+#!/usr/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1989 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+# All Rights Reserved
+
+# University Copyright- Copyright (c) 1982, 1986, 1988
+# The Regents of the University of California
+# All Rights Reserved
+#
+# University Acknowledgment- Portions of this document are derived from
+# software developed by the University of California, Berkeley, and its
+# contributors.
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+
+# lint command for BSD compatibility package:
+#
+# BSD compatibility package header files (/usr/ucbinclude)
+# are included before SVr4 default (/usr/include) files but
+# after any directories specified on the command line via
+# the -I option. Thus, the BSD header files are included
+# next to last, and SVr4 header files are searched last.
+#
+# BSD compatibility package libraries are searched first.
+#
+# Because the BSD compatibility package C lint library does not
+# contain all the C library routines of /usr/ccs/lib/llib-lc,
+# the BSD package C library is named /usr/ucblib/llib-lucb
+# and is passed explicitly to lint. This ensures that llib-lucb
+# will be searched first for routines and that
+# /usr/ccs/lib/llib-lc will be searched afterwards for routines
+# not found in /usr/ucblib/llib-lucb. Also because sockets is
+# provided in libc under BSD, /usr/lib/llib-lsocket and
+# /usr/lib/llib-lnsl are also included as default libraries.
+#
+# Note: Lint does not allow you to reset the search PATH for
+# libraries. The following uses the -L option to point to
+# /usr/ucblib. There are however some combinations of options
+# specified by the user that could overrule the intended path.
+#
+
+if [ -f /usr/ccs/bin/ucblint ]
+then
+ /usr/ccs/bin/ucblint -L/usr/ucblib -Xs "$@" -I/usr/ucbinclude \
+ -L/usr/ucblib -lucb -lsocket -lnsl -lelf
+ ret=$?
+ exit $ret
+else
+ echo "/usr/ucb/lint: language optional software not installed"
+ exit 1
+fi
diff --git a/usr/src/ucbcmd/ln/Makefile b/usr/src/ucbcmd/ln/Makefile
new file mode 100644
index 0000000000..f1c082b821
--- /dev/null
+++ b/usr/src/ucbcmd/ln/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= ln
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/ln/ln.c b/usr/src/ucbcmd/ln/ln.c
new file mode 100644
index 0000000000..6bf02b82da
--- /dev/null
+++ b/usr/src/ucbcmd/ln/ln.c
@@ -0,0 +1,122 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * ln
+ */
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+struct stat stb;
+int fflag; /* force flag set? */
+int sflag;
+extern int errno;
+
+main(argc, argv)
+ int argc;
+ register char **argv;
+{
+ register int i, r;
+
+ argc--, argv++;
+again:
+ if (argc && strcmp(argv[0], "-f") == 0) {
+ fflag++;
+ argv++;
+ argc--;
+ }
+ if (argc && strcmp(argv[0], "-s") == 0) {
+ sflag++;
+ argv++;
+ argc--;
+ }
+ if (argc == 0)
+ goto usage;
+ else if (argc == 1) {
+ argv[argc] = ".";
+ argc++;
+ }
+ if (argc > 2) {
+ if (stat(argv[argc-1], &stb) < 0)
+ goto usage;
+ if ((stb.st_mode&S_IFMT) != S_IFDIR)
+ goto usage;
+ }
+ r = 0;
+ for(i = 0; i < argc-1; i++)
+ r |= linkit(argv[i], argv[argc-1]);
+ exit(r);
+usage:
+ (void) fprintf(stderr,
+ "Usage: ln [-f] [-s] f1\n\
+ ln [-f] [-s] f1 f2\n\
+ ln [-f] [-s] f1 ... fn d1\n");
+ exit(1);
+}
+
+int link(), symlink();
+
+linkit(from, to)
+ char *from, *to;
+{
+ char destname[MAXPATHLEN + 1];
+ char *tail;
+ int (*linkf)() = sflag ? symlink : link;
+ char *strrchr();
+
+ /* is target a directory? */
+ if (sflag == 0 && fflag == 0 && stat(from, &stb) >= 0
+ && (stb.st_mode&S_IFMT) == S_IFDIR) {
+ printf("%s is a directory\n", from);
+ return (1);
+ }
+ if (stat(to, &stb) >= 0 && (stb.st_mode&S_IFMT) == S_IFDIR) {
+ tail = strrchr(from, '/');
+ if (tail == 0)
+ tail = from;
+ else
+ tail++;
+ if (strlen(to) + strlen(tail) >= sizeof destname - 1) {
+ (void) fprintf(stderr, "ln: %s/%s: Name too long\n",
+ to, tail);
+ return (1);
+ }
+ (void) sprintf(destname, "%s/%s", to, tail);
+ to = destname;
+ }
+ if ((*linkf)(from, to) < 0) {
+ if (errno == EEXIST || sflag)
+ Perror(to);
+ else if (access(from, 0) < 0)
+ Perror(from);
+ else
+ Perror(to);
+ return (1);
+ }
+ return (0);
+}
+
+Perror(s)
+ char *s;
+{
+
+ (void) fprintf(stderr, "ln: ");
+ perror(s);
+}
diff --git a/usr/src/ucbcmd/ls/Makefile b/usr/src/ucbcmd/ls/Makefile
new file mode 100644
index 0000000000..323e1e38a0
--- /dev/null
+++ b/usr/src/ucbcmd/ls/Makefile
@@ -0,0 +1,49 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ucbcmd/ls/Makefile
+
+PROG= ls
+
+include ../Makefile.ucbcmd
+
+CFLAGS += $(CCVERBOSE)
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/ls/ls.c b/usr/src/ucbcmd/ls/ls.c
new file mode 100644
index 0000000000..0f65f61f25
--- /dev/null
+++ b/usr/src/ucbcmd/ls/ls.c
@@ -0,0 +1,841 @@
+/*
+ * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * ls
+ *
+ * 4.2bsd version for symbolic links, variable length
+ * directory entries, block size in the inode, etc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <time.h>
+#include <limits.h>
+#include <locale.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/termios.h>
+#include <sys/mkdev.h>
+#include <sys/acl.h>
+
+#define dbtokb(nb) ((nb) / (1024 / DEV_BSIZE))
+
+struct afile {
+ char ftype; /* file type, e.g. 'd', 'c', 'f' */
+ ino_t fnum; /* inode number of file */
+ short fflags; /* mode&~S_IFMT, perhaps ISARG */
+ nlink_t fnl; /* number of links */
+ uid_t fuid; /* owner id */
+ gid_t fgid; /* group id */
+ off_t fsize; /* file size */
+ blkcnt_t fblks; /* number of blocks used */
+ time_t fmtime; /* time (modify or access or create) */
+ char *fname; /* file name */
+ char *flinkto; /* symbolic link value */
+ char acl; /* acl access flag */
+};
+
+#define ISARG 0x8000 /* extra ``mode'' */
+
+static struct subdirs {
+ char *sd_name;
+ struct subdirs *sd_next;
+} *subdirs;
+
+static int aflg, dflg, gflg, lflg, sflg, tflg, uflg, iflg, fflg, cflg;
+static int rflg = 1;
+static int qflg, Aflg, Cflg, Fflg, Lflg, Rflg;
+
+static int usetabs;
+
+static time_t now, sixmonthsago, onehourfromnow;
+
+static char *dotp = ".";
+
+static struct winsize win;
+static int twidth;
+
+static struct afile *gstat(struct afile *, char *, int, off_t *);
+static int fcmp(const void *, const void *);
+static char *cat(char *, char *);
+static char *savestr(char *);
+static char *fmtentry(struct afile *);
+static char *getname(), *getgroup();
+static void formatd(char *, int);
+static void formatf(struct afile *, struct afile *);
+static off_t getdir(char *, struct afile **, struct afile **);
+
+int
+main(int argc, char **argv)
+{
+ int i;
+ struct afile *fp0, *fplast;
+ register struct afile *fp;
+ struct termios trbuf;
+
+ argc--, argv++;
+ if (getuid() == 0)
+ Aflg++;
+ (void) time(&now);
+ sixmonthsago = now - 6L*30L*24L*60L*60L;
+ onehourfromnow = now + 60L*60L;
+ now += 60;
+ twidth = 80;
+ if (isatty(1)) {
+ qflg = Cflg = 1;
+ (void) ioctl(1, TCGETS, &trbuf);
+ if (ioctl(1, TIOCGWINSZ, &win) != -1)
+ twidth = (win.ws_col == 0 ? 80 : win.ws_col);
+ if ((trbuf.c_oflag & TABDLY) != TAB3)
+ usetabs = 1;
+ } else
+ usetabs = 1;
+
+ (void) setlocale(LC_ALL, ""); /* set local environment */
+
+ while (argc > 0 && **argv == '-') {
+ (*argv)++;
+ while (**argv) {
+ switch (*(*argv)++) {
+ case 'C':
+ Cflg = 1; break;
+ case 'q':
+ qflg = 1; break;
+ case '1':
+ Cflg = 0; break;
+ case 'a':
+ aflg++; break;
+ case 'A':
+ Aflg++; break;
+ case 'c':
+ cflg++; break;
+ case 's':
+ sflg++; break;
+ case 'd':
+ dflg++; break;
+ case 'g':
+ gflg++; break;
+ case 'l':
+ lflg++; break;
+ case 'r':
+ rflg = -1; break;
+ case 't':
+ tflg++; break;
+ case 'u':
+ uflg++; break;
+ case 'i':
+ iflg++; break;
+ case 'f':
+ fflg++; break;
+ case 'L':
+ Lflg++; break;
+ case 'F':
+ Fflg++; break;
+ case 'R':
+ Rflg++; break;
+ }
+ }
+ argc--, argv++;
+ }
+ if (fflg) {
+ aflg++; lflg = 0; sflg = 0; tflg = 0;
+ }
+ if (lflg)
+ Cflg = 0;
+ if (argc == 0) {
+ argc++;
+ argv = &dotp;
+ }
+ fp = (struct afile *)calloc(argc, sizeof (struct afile));
+ if (fp == 0) {
+ (void) fprintf(stderr, "ls: out of memory\n");
+ exit(1);
+ }
+ fp0 = fp;
+ for (i = 0; i < argc; i++) {
+ if (gstat(fp, *argv, 1, (off_t *)0)) {
+ fp->fname = *argv;
+ fp->fflags |= ISARG;
+ fp++;
+ }
+ argv++;
+ }
+ fplast = fp;
+ qsort(fp0, fplast - fp0, sizeof (struct afile), fcmp);
+ if (dflg) {
+ formatf(fp0, fplast);
+ exit(0);
+ }
+ if (fflg)
+ fp = fp0;
+ else {
+ for (fp = fp0; fp < fplast && fp->ftype != 'd'; fp++)
+ continue;
+ formatf(fp0, fp);
+ }
+ if (fp < fplast) {
+ if (fp > fp0)
+ (void) printf("\n");
+ for (;;) {
+ formatd(fp->fname, argc > 1);
+ while (subdirs) {
+ struct subdirs *t;
+
+ t = subdirs; subdirs = t->sd_next;
+ (void) printf("\n");
+ formatd(t->sd_name, 1);
+ free(t->sd_name);
+ free(t);
+ }
+ if (++fp == fplast)
+ break;
+ (void) printf("\n");
+ }
+ }
+ return (0);
+}
+
+static void
+formatd(char *name, int title)
+{
+ register struct afile *fp;
+ register struct subdirs *dp;
+ struct afile *dfp0, *dfplast;
+ off_t nkb;
+
+ nkb = getdir(name, &dfp0, &dfplast);
+ if (dfp0 == 0)
+ return;
+ if (fflg == 0)
+ qsort(dfp0, dfplast - dfp0, sizeof (struct afile), fcmp);
+ if (title)
+ (void) printf("%s:\n", name);
+ if (lflg || sflg)
+ (void) printf("total %lld\n", nkb);
+ formatf(dfp0, dfplast);
+ if (Rflg)
+ for (fp = dfplast - 1; fp >= dfp0; fp--) {
+ if (fp->ftype != 'd' ||
+ strcmp(fp->fname, ".") == 0 ||
+ strcmp(fp->fname, "..") == 0)
+ continue;
+ dp = (struct subdirs *)malloc(sizeof (struct subdirs));
+ dp->sd_name = savestr(cat(name, fp->fname));
+ dp->sd_next = subdirs; subdirs = dp;
+ }
+ for (fp = dfp0; fp < dfplast; fp++) {
+ if ((fp->fflags&ISARG) == 0 && fp->fname)
+ free(fp->fname);
+ if (fp->flinkto)
+ free(fp->flinkto);
+ }
+ free(dfp0);
+}
+
+static off_t
+getdir(char *dir, struct afile **pfp0, struct afile **pfplast)
+{
+ register struct afile *fp;
+ DIR *dirp;
+ register struct dirent *dp;
+ off_t nb;
+ size_t nent = 20;
+
+ /*
+ * This code (opendir, readdir, and the "for" loop) is arranged in
+ * this strange manner to handle the case where UNIX lets root open
+ * any directory for reading, but NFS does not let root read the
+ * openned directory.
+ */
+ *pfp0 = *pfplast = NULL;
+ if ((dirp = opendir(dir)) == NULL) {
+ (void) printf("%s unreadable\n", dir); /* not stderr! */
+ return (0);
+ }
+ errno = 0;
+ if (((dp = readdir(dirp)) == NULL) && (errno != 0)) {
+ /* root reading across NFS can get to this error case */
+ (void) printf("%s unreadable\n", dir); /* not stderr! */
+ (void) closedir(dirp);
+ return (0);
+ }
+ fp = *pfp0 = (struct afile *)calloc(nent, sizeof (struct afile));
+ *pfplast = *pfp0 + nent;
+ for (nb = 0; dp != NULL; dp = readdir(dirp)) {
+ if (dp->d_ino == 0)
+ continue;
+ if (aflg == 0 && dp->d_name[0] == '.' &&
+ (Aflg == 0 || dp->d_name[1] == 0 ||
+ dp->d_name[1] == '.' && dp->d_name[2] == 0))
+ continue;
+ if (gstat(fp, cat(dir, dp->d_name), Fflg+Rflg, &nb) == 0)
+ continue;
+ fp->fnum = dp->d_ino;
+ fp->fname = savestr(dp->d_name);
+ fp++;
+ if (fp == *pfplast) {
+ *pfp0 = (struct afile *)realloc((char *)*pfp0,
+ 2 * nent * sizeof (struct afile));
+ if (*pfp0 == 0) {
+ (void) fprintf(stderr, "ls: out of memory\n");
+ exit(1);
+ }
+ fp = *pfp0 + nent;
+ *pfplast = fp + nent;
+ nent *= 2;
+ }
+ }
+ (void) closedir(dirp);
+ *pfplast = fp;
+ return (dbtokb(nb));
+}
+
+
+static struct afile *
+gstat(struct afile *fp, char *file, int statarg, off_t *pnb)
+{
+ static struct afile azerofile;
+ int (*statf)() = Lflg ? stat : lstat;
+ int cc;
+ char buf[PATH_MAX];
+ int aclcnt;
+ aclent_t *aclp;
+ aclent_t *tp;
+ o_mode_t groupperm, mask;
+ int grouppermfound, maskfound;
+
+ *fp = azerofile;
+ fp->fflags = 0;
+ fp->fnum = 0;
+ fp->ftype = '-';
+ if (statarg || sflg || lflg || tflg) {
+ struct stat stb, stb1;
+
+ if ((*statf)(file, &stb) < 0) {
+ if (statf == lstat || lstat(file, &stb) < 0) {
+ if (errno == ENOENT)
+ (void) fprintf(stderr,
+ "%s not found\n", file);
+ else {
+ (void) fprintf(stderr, "ls: ");
+ perror(file);
+ }
+ return (0);
+ }
+ }
+ fp->fblks = stb.st_blocks;
+ fp->fsize = stb.st_size;
+ switch (stb.st_mode & S_IFMT) {
+ case S_IFDIR:
+ fp->ftype = 'd'; break;
+ case S_IFDOOR:
+ fp->ftype = 'D'; break;
+ case S_IFBLK:
+ fp->ftype = 'b'; fp->fsize = (off_t)stb.st_rdev; break;
+ case S_IFCHR:
+ fp->ftype = 'c'; fp->fsize = (off_t)stb.st_rdev; break;
+ case S_IFSOCK:
+ fp->ftype = 's'; fp->fsize = 0LL; break;
+ case S_IFIFO:
+ fp->ftype = 'p'; fp->fsize = 0LL; break;
+ case S_IFLNK:
+ fp->ftype = 'l';
+ if (lflg) {
+ cc = readlink(file, buf, BUFSIZ);
+ if (cc >= 0) {
+ /*
+ * here we follow the symbolic
+ * link to generate the proper
+ * Fflg marker for the object,
+ * eg, /bin -> /pub/bin/
+ */
+ buf[cc] = 0;
+ if (Fflg && !stat(file, &stb1))
+ switch (stb1.st_mode & S_IFMT) {
+ case S_IFDIR:
+ buf[cc++] = '/';
+ break;
+ case S_IFDOOR:
+ buf[cc++] = '>';
+ break;
+ case S_IFIFO:
+ buf[cc++] = '|';
+ break;
+ case S_IFSOCK:
+ buf[cc++] = '=';
+ break;
+ default:
+ if ((stb1.st_mode & ~S_IFMT)
+ & 0111)
+ buf[cc++] = '*';
+ break;
+ }
+ buf[cc] = 0;
+ fp->flinkto = savestr(buf);
+ }
+ break;
+ }
+ /*
+ * this is a hack from UCB to avoid having
+ * ls /bin behave differently from ls /bin/
+ * when /bin is a symbolic link. We hack the
+ * hack to have that happen, but only for
+ * explicit arguments, by inspecting pnb.
+ */
+ if (pnb != (off_t *)0 || stat(file, &stb1) < 0)
+ break;
+ if ((stb1.st_mode & S_IFMT) == S_IFDIR) {
+ stb = stb1;
+ fp->ftype = 'd';
+ fp->fsize = stb.st_size;
+ fp->fblks = stb.st_blocks;
+ }
+ break;
+ }
+ fp->fnum = stb.st_ino;
+ fp->fflags = stb.st_mode & ~S_IFMT;
+ fp->fnl = stb.st_nlink;
+ fp->fuid = stb.st_uid;
+ fp->fgid = stb.st_gid;
+
+ /* ACL: check acl entries count */
+ if ((aclcnt = acl(file, GETACLCNT, 0, NULL)) >
+ MIN_ACL_ENTRIES) {
+
+ /* this file has a non-trivial acl */
+
+ fp->acl = '+';
+
+ /*
+ * For files with non-trivial acls, the
+ * effective group permissions are the
+ * intersection of the GROUP_OBJ value and
+ * the CLASS_OBJ (acl mask) value. Determine
+ * both the GROUP_OBJ and CLASS_OBJ for this
+ * file and insert the logical AND of those
+ * two values in the group permissions field
+ * of the lflags value for this file.
+ */
+
+ if ((aclp = (aclent_t *)malloc(
+ (sizeof (aclent_t)) * aclcnt)) == NULL) {
+ perror("ls");
+ exit(2);
+ }
+
+ if (acl(file, GETACL, aclcnt, aclp) < 0) {
+ free(aclp);
+ (void) fprintf(stderr, "ls: ");
+ perror(file);
+ return (0);
+ }
+
+ /*
+ * Until found in acl list, assume maximum
+ * permissions for both group and mask. (Just
+ * in case the acl lacks either value for
+ * some reason.)
+ */
+ groupperm = 07;
+ mask = 07;
+ grouppermfound = 0;
+ maskfound = 0;
+ for (tp = aclp; aclcnt--; tp++) {
+ if (tp->a_type == GROUP_OBJ) {
+ groupperm = tp->a_perm;
+ grouppermfound = 1;
+ continue;
+ }
+ if (tp->a_type == CLASS_OBJ) {
+ mask = tp->a_perm;
+ maskfound = 1;
+ }
+ if (grouppermfound && maskfound)
+ break;
+ }
+
+ free(aclp);
+
+ /* reset all the group bits */
+ fp->fflags &= ~S_IRWXG;
+
+ /*
+ * Now set them to the logical AND of the
+ * GROUP_OBJ permissions and the acl mask.
+ */
+
+ fp->fflags |= (groupperm & mask) << 3;
+ } else
+ fp->acl = ' ';
+
+ if (uflg)
+ fp->fmtime = stb.st_atime;
+ else if (cflg)
+ fp->fmtime = stb.st_ctime;
+ else
+ fp->fmtime = stb.st_mtime;
+ if (pnb)
+ *pnb += stb.st_blocks;
+ }
+ return (fp);
+}
+
+static void
+formatf(struct afile *fp0, struct afile *fplast)
+{
+ register struct afile *fp;
+ int width = 0, w, nentry = fplast - fp0;
+ int i, j, columns, lines;
+ char *cp;
+
+ if (fp0 == fplast)
+ return;
+ if (lflg || Cflg == 0)
+ columns = 1;
+ else {
+ for (fp = fp0; fp < fplast; fp++) {
+ int len = strlen(fmtentry(fp));
+
+ if (len > width)
+ width = len;
+ }
+ if (usetabs)
+ width = (width + 8) &~ 7;
+ else
+ width += 2;
+ columns = twidth / width;
+ if (columns == 0)
+ columns = 1;
+ }
+ lines = (nentry + columns - 1) / columns;
+ for (i = 0; i < lines; i++) {
+ for (j = 0; j < columns; j++) {
+ fp = fp0 + j * lines + i;
+ cp = fmtentry(fp);
+ (void) printf("%s", cp);
+ if (fp + lines >= fplast) {
+ (void) printf("\n");
+ break;
+ }
+ w = strlen(cp);
+ while (w < width)
+ if (usetabs) {
+ w = (w + 8) &~ 7;
+ (void) putchar('\t');
+ } else {
+ w++;
+ (void) putchar(' ');
+ }
+ }
+ }
+}
+
+static int
+fcmp(const void *arg1, const void *arg2)
+{
+ const struct afile *f1 = arg1;
+ const struct afile *f2 = arg2;
+
+ if (dflg == 0 && fflg == 0) {
+ if ((f1->fflags&ISARG) && f1->ftype == 'd') {
+ if ((f2->fflags&ISARG) == 0 || f2->ftype != 'd')
+ return (1);
+ } else {
+ if ((f2->fflags&ISARG) && f2->ftype == 'd')
+ return (-1);
+ }
+ }
+ if (tflg) {
+ if (f2->fmtime == f1->fmtime)
+ return (0);
+ if (f2->fmtime > f1->fmtime)
+ return (rflg);
+ return (-rflg);
+ }
+ return (rflg * strcmp(f1->fname, f2->fname));
+}
+
+static char *
+cat(char *dir, char *file)
+{
+ static char dfile[BUFSIZ];
+
+ if (strlen(dir)+1+strlen(file)+1 > BUFSIZ) {
+ (void) fprintf(stderr, "ls: filename too long\n");
+ exit(1);
+ }
+ if (strcmp(dir, "") == 0 || strcmp(dir, ".") == 0) {
+ (void) strcpy(dfile, file);
+ return (dfile);
+ }
+ (void) strcpy(dfile, dir);
+ if (dir[strlen(dir) - 1] != '/' && *file != '/')
+ (void) strcat(dfile, "/");
+ (void) strcat(dfile, file);
+ return (dfile);
+}
+
+static char *
+savestr(char *str)
+{
+ char *cp = malloc(strlen(str) + 1);
+
+ if (cp == NULL) {
+ (void) fprintf(stderr, "ls: out of memory\n");
+ exit(1);
+ }
+ (void) strcpy(cp, str);
+ return (cp);
+}
+
+static char *fmtinum(struct afile *);
+static char *fmtsize(struct afile *);
+static char *fmtlstuff(struct afile *);
+static char *fmtmode(char *, int);
+
+static char *
+fmtentry(struct afile *fp)
+{
+ static char fmtres[BUFSIZ];
+ register char *cp, *dp;
+
+ (void) sprintf(fmtres, "%s%s%s",
+ iflg ? fmtinum(fp) : "",
+ sflg ? fmtsize(fp) : "",
+ lflg ? fmtlstuff(fp) : "");
+ dp = &fmtres[strlen(fmtres)];
+ for (cp = fp->fname; *cp; cp++)
+ if (qflg && !isprint((unsigned char)*cp))
+ *dp++ = '?';
+ else
+ *dp++ = *cp;
+ /* avoid both "->" and trailing marks */
+ if (Fflg && ! (lflg && fp->flinkto)) {
+ if (fp->ftype == 'd')
+ *dp++ = '/';
+ else if (fp->ftype == 'D')
+ *dp++ = '>';
+ else if (fp->ftype == 'p')
+ *dp++ = '|';
+ else if (fp->ftype == 'l')
+ *dp++ = '@';
+ else if (fp->ftype == 's')
+ *dp++ = '=';
+ else if (fp->fflags & 0111)
+ *dp++ = '*';
+ }
+ if (lflg && fp->flinkto) {
+ (void) strcpy(dp, " -> "); dp += 4;
+ for (cp = fp->flinkto; *cp; cp++)
+ if (qflg && !isprint((unsigned char) *cp))
+ *dp++ = '?';
+ else
+ *dp++ = *cp;
+ }
+ *dp++ = 0;
+ return (fmtres);
+}
+
+static char *
+fmtinum(struct afile *p)
+{
+ static char inumbuf[12];
+
+ (void) sprintf(inumbuf, "%10llu ", p->fnum);
+ return (inumbuf);
+}
+
+static char *
+fmtsize(struct afile *p)
+{
+ static char sizebuf[32];
+
+ (void) sprintf(sizebuf, (off_t)dbtokb(p->fblks) < 10000 ? "%4lld " : \
+ "%lld ", (off_t)dbtokb(p->fblks));
+ return (sizebuf);
+}
+
+static char *
+fmtlstuff(struct afile *p)
+{
+ static char lstuffbuf[256];
+ char gname[32], uname[32], fsize[32], ftime[32];
+ register char *lp = lstuffbuf;
+
+ /* type mode uname gname fsize ftime */
+/* get uname */
+ {
+ char *cp = getname(p->fuid);
+ (void) sprintf(uname, "%-9s", cp);
+ }
+/* get gname */
+ if (gflg) {
+ char *cp = getgroup(p->fgid);
+ (void) sprintf(gname, "%-9s", cp);
+ }
+/* get fsize */
+ if (p->ftype == 'b' || p->ftype == 'c')
+ (void) sprintf(fsize, "%3ld,%4ld",
+ major(p->fsize), minor(p->fsize));
+ else if (p->ftype == 's')
+ (void) sprintf(fsize, "%8d", 0);
+ else
+ (void) sprintf(fsize, p->fsize < 100000000 ? "%8lld" : \
+ "%lld", p->fsize);
+/* get ftime */
+ {
+ char *cp = ctime(&p->fmtime);
+ if ((p->fmtime < sixmonthsago) || (p->fmtime > onehourfromnow))
+ (void) sprintf(ftime, " %-7.7s %-4.4s ", cp+4, cp+20);
+ else
+ (void) sprintf(ftime, " %-12.12s ", cp+4);
+ }
+/* splat */
+ *lp++ = p->ftype;
+ lp = fmtmode(lp, p->fflags);
+ (void) sprintf(lp, "%c%3ld %s%s%s%s",
+ p->acl, p->fnl, uname, gflg ? gname : "", fsize, ftime);
+ return (lstuffbuf);
+}
+
+static int m1[] =
+ { 1, S_IREAD>>0, 'r', '-' };
+static int m2[] =
+ { 1, S_IWRITE>>0, 'w', '-' };
+static int m3[] =
+ { 3, S_ISUID|(S_IEXEC>>0), 's', S_IEXEC>>0, 'x', S_ISUID, 'S', '-' };
+static int m4[] =
+ { 1, S_IREAD>>3, 'r', '-' };
+static int m5[] =
+ { 1, S_IWRITE>>3, 'w', '-' };
+static int m6[] =
+ { 3, S_ISGID|(S_IEXEC>>3), 's', S_IEXEC>>3, 'x', S_ISGID, 'S', '-' };
+static int m7[] =
+ { 1, S_IREAD>>6, 'r', '-' };
+static int m8[] =
+ { 1, S_IWRITE>>6, 'w', '-' };
+static int m9[] =
+ { 3, S_ISVTX|(S_IEXEC>>6), 't', S_ISVTX, 'T', S_IEXEC>>6, 'x', '-' };
+
+static int *m[] = { m1, m2, m3, m4, m5, m6, m7, m8, m9};
+
+static char *
+fmtmode(char *lp, int flags)
+{
+ int **mp;
+
+ for (mp = &m[0]; mp < &m[sizeof (m)/sizeof (m[0])]; ) {
+ register int *pairp = *mp++;
+ register int n = *pairp++;
+
+ while (n-- > 0) {
+ if ((flags&*pairp) == *pairp) {
+ pairp++;
+ break;
+ } else
+ pairp += 2;
+ }
+ *lp++ = *pairp;
+ }
+ return (lp);
+}
+
+/* rest should be done with nameserver or database */
+
+#include <pwd.h>
+#include <grp.h>
+#include <utmpx.h>
+
+#define NMAX (sizeof (((struct utmpx *)0)->ut_name))
+#define SCPYN(a, b) strncpy(a, b, NMAX)
+
+
+static struct cachenode { /* this struct must be zeroed before using */
+ struct cachenode *lesschild; /* subtree whose entries < val */
+ struct cachenode *grtrchild; /* subtree whose entries > val */
+ int val; /* the uid or gid of this entry */
+ int initted; /* name has been filled in */
+ char name[NMAX+1]; /* the string that val maps to */
+} *names, *groups;
+
+static struct cachenode *
+findincache(struct cachenode **head, id_t val)
+{
+ register struct cachenode **parent = head;
+ register struct cachenode *c = *parent;
+
+ while (c != NULL) {
+ if (val == c->val) {
+ /* found it */
+ return (c);
+ } else if (val < c->val) {
+ parent = &c->lesschild;
+ c = c->lesschild;
+ } else {
+ parent = &c->grtrchild;
+ c = c->grtrchild;
+ }
+ }
+
+ /* not in the cache, make a new entry for it */
+ *parent = c = (struct cachenode *)calloc(1, sizeof (struct cachenode));
+ c->val = val;
+ return (c);
+}
+
+static char *
+getname(uid_t uid)
+{
+ struct cachenode *c;
+ struct passwd *pw;
+
+ c = findincache(&names, uid);
+ if (c->initted == 0) {
+ if ((pw = getpwuid(uid)) != NULL) {
+ (void) SCPYN(&c->name[0], pw->pw_name);
+ } else {
+ (void) sprintf(&c->name[0], "%-8lu ", uid);
+ }
+ c->initted = 1;
+ }
+ return (&c->name[0]);
+}
+
+static char *
+getgroup(gid_t gid)
+{
+ struct cachenode *c;
+ struct group *gr;
+
+ c = findincache(&groups, gid);
+ if (c->initted == 0) {
+ if ((gr = getgrgid(gid)) != NULL) {
+ (void) SCPYN(&c->name[0], gr->gr_name);
+ } else {
+ (void) sprintf(&c->name[0], "%-8lu ", gid);
+ }
+ c->initted = 1;
+ }
+ return (&c->name[0]);
+}
diff --git a/usr/src/ucbcmd/mach/Makefile b/usr/src/ucbcmd/mach/Makefile
new file mode 100644
index 0000000000..eb7a26b2f9
--- /dev/null
+++ b/usr/src/ucbcmd/mach/Makefile
@@ -0,0 +1,52 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+SHFILES= mach
+CLOBBERFILES= $(SHFILES)
+
+SHSRCS= $(SHFILES:%=%.sh)
+
+include ../Makefile.ucbcmd
+
+.KEEP_STATE:
+
+all: $(SHFILES)
+
+%: %.sh
+ $(RM) $@
+ $(CP) $< $@
+
+# Don't re-install directories already installed by Targetdirs
+#install: all $(ROOTBIN) $(ROOTSHFILES)
+install: all $(ROOTSHFILES)
+
+clean:
+
+lint:
+
+include ../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/mkstr/Makefile b/usr/src/ucbcmd/mkstr/Makefile
new file mode 100644
index 0000000000..3e0d2accc9
--- /dev/null
+++ b/usr/src/ucbcmd/mkstr/Makefile
@@ -0,0 +1,45 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= mkstr
+
+include ../Makefile.ucbcmd
+#
+# For messaging
+XGETFLAGS += -a -x mkstr.xcl
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/mkstr/mkstr.c b/usr/src/ucbcmd/mkstr/mkstr.c
new file mode 100644
index 0000000000..a3ca0cac9e
--- /dev/null
+++ b/usr/src/ucbcmd/mkstr/mkstr.c
@@ -0,0 +1,303 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright 1992 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+ /* from UCB 4.1 10/01/80 */
+#include <stdio.h>
+#include <locale.h>
+
+#define ungetchar(c) ungetc(c, stdin)
+
+long ftell();
+char *calloc();
+/*
+ * mkstr - create a string error message file by massaging C source
+ *
+ * Bill Joy UCB August 1977
+ *
+ * Modified March 1978 to hash old messages to be able to recompile
+ * without addding messages to the message file (usually)
+ *
+ * Based on an earlier program conceived by Bill Joy and Chuck Haley
+ *
+ * Program to create a string error message file
+ * from a group of C programs. Arguments are the name
+ * of the file where the strings are to be placed, the
+ * prefix of the new files where the processed source text
+ * is to be placed, and the files to be processed.
+ *
+ * The program looks for 'error("' in the source stream.
+ * Whenever it finds this, the following characters from the '"'
+ * to a '"' are replaced by 'seekpt' where seekpt is a
+ * pointer into the error message file.
+ * If the '(' is not immediately followed by a '"' no change occurs.
+ *
+ * The optional '-' causes strings to be added at the end of the
+ * existing error message file for recompilation of single routines.
+ */
+
+
+FILE *mesgread, *mesgwrite;
+char *progname;
+char usagestr[] = "usage: %s [ - ] mesgfile prefix file ...\n";
+char name[100], *np;
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ char addon = 0;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ argc--, progname = *argv++;
+ if (argc > 1 && argv[0][0] == '-')
+ addon++, argc--, argv++;
+ if (argc < 3)
+ fprintf(stderr, gettext(usagestr), progname), exit(1);
+ mesgwrite = fopen(argv[0], addon ? "a" : "w");
+ if (mesgwrite == NULL)
+ perror(argv[0]), exit(1);
+ mesgread = fopen(argv[0], "r");
+ if (mesgread == NULL)
+ perror(argv[0]), exit(1);
+ inithash();
+ argc--, argv++;
+ strcpy(name, argv[0]);
+ np = name + strlen(name);
+ argc--, argv++;
+ do {
+ strcpy(np, argv[0]);
+ if (freopen(name, "w", stdout) == NULL)
+ perror(name), exit(1);
+ if (freopen(argv[0], "r", stdin) == NULL)
+ perror(argv[0]), exit(1);
+ process();
+ argc--, argv++;
+ } while (argc > 0);
+ exit(0);
+ /* NOTREACHED */
+}
+
+process()
+{
+ register char *cp;
+ register c;
+
+ for (;;) {
+ c = getchar();
+ if (c == EOF)
+ return;
+ if (c != 'e') {
+ putchar(c);
+ continue;
+ }
+ if (match("error(")) {
+ printf(gettext("error("));
+ c = getchar();
+ if (c != '"')
+ putchar(c);
+ else
+ copystr();
+ }
+ }
+}
+
+match(ocp)
+ char *ocp;
+{
+ register char *cp;
+ register c;
+
+ for (cp = ocp + 1; *cp; cp++) {
+ c = getchar();
+ if (c != *cp) {
+ while (ocp < cp)
+ putchar(*ocp++);
+ ungetchar(c);
+ return (0);
+ }
+ }
+ return (1);
+}
+
+copystr()
+{
+ register c, ch;
+ char buf[512];
+ register char *cp = buf;
+
+ for (;;) {
+ c = getchar();
+ if (c == EOF)
+ break;
+ switch (c) {
+
+ case '"':
+ *cp++ = 0;
+ goto out;
+ case '\\':
+ c = getchar();
+ switch (c) {
+
+ case 'b':
+ c = '\b';
+ break;
+ case 't':
+ c = '\t';
+ break;
+ case 'r':
+ c = '\r';
+ break;
+ case 'n':
+ c = '\n';
+ break;
+ case '\n':
+ continue;
+ case 'f':
+ c = '\f';
+ break;
+ case '0':
+ c = 0;
+ break;
+ case '\\':
+ break;
+ default:
+ if (!octdigit(c))
+ break;
+ c -= '0';
+ ch = getchar();
+ if (!octdigit(ch))
+ break;
+ c <<= 7, c += ch - '0';
+ ch = getchar();
+ if (!octdigit(ch))
+ break;
+ c <<= 3, c+= ch - '0', ch = -1;
+ break;
+ }
+ }
+ *cp++ = c;
+ }
+out:
+ *cp = 0;
+ printf("%d", hashit(buf, 1, NULL));
+}
+
+octdigit(c)
+ char c;
+{
+
+ return (c >= '0' && c <= '7');
+}
+
+inithash()
+{
+ char buf[512];
+ int mesgpt = 0;
+
+ rewind(mesgread);
+ while (fgetNUL(buf, sizeof buf, mesgread) != NULL) {
+ hashit(buf, 0, mesgpt);
+ mesgpt += strlen(buf) + 2;
+ }
+}
+
+#define NBUCKETS 511
+
+struct hash {
+ long hval;
+ unsigned hpt;
+ struct hash *hnext;
+} *bucket[NBUCKETS];
+
+hashit(str, really, fakept)
+ char *str;
+ char really;
+ unsigned fakept;
+{
+ int i;
+ register struct hash *hp;
+ char buf[512];
+ long hashval = 0;
+ register char *cp;
+
+ if (really)
+ fflush(mesgwrite);
+ for (cp = str; *cp;)
+ hashval = (hashval << 1) + *cp++;
+ i = hashval % NBUCKETS;
+ if (i < 0)
+ i += NBUCKETS;
+ if (really != 0)
+ for (hp = bucket[i]; hp != 0; hp = hp->hnext)
+ if (hp->hval == hashval) {
+ fseek(mesgread, (long) hp->hpt, 0);
+ fgetNUL(buf, sizeof buf, mesgread);
+/*
+ fprintf(stderr, gettext("Got (from %d) %s\n"), hp->hpt, buf);
+*/
+ if (strcmp(buf, str) == 0)
+ break;
+ }
+ if (!really || hp == 0) {
+ hp = (struct hash *) calloc(1, sizeof *hp);
+ hp->hnext = bucket[i];
+ hp->hval = hashval;
+ hp->hpt = really ? ftell(mesgwrite) : fakept;
+ if (really) {
+ fwrite(str, sizeof (char), strlen(str) + 1, mesgwrite);
+ fwrite("\n", sizeof (char), 1, mesgwrite);
+ }
+ bucket[i] = hp;
+ }
+/*
+ fprintf(stderr, gettext("%s hashed to %ld at %d\n"), str, hp->hval, hp->hpt);
+*/
+ return (hp->hpt);
+}
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+fgetNUL(obuf, rmdr, file)
+ char *obuf;
+ register int rmdr;
+ FILE *file;
+{
+ register c;
+ register char *buf = obuf;
+
+ while (--rmdr > 0 && (c = getc(file)) != 0 && c != EOF)
+ *buf++ = c;
+ *buf++ = 0;
+ getc(file);
+ return ((feof(file) || ferror(file)) ? NULL : 1);
+}
diff --git a/usr/src/ucbcmd/mkstr/mkstr.xcl b/usr/src/ucbcmd/mkstr/mkstr.xcl
new file mode 100644
index 0000000000..e7baac6ac9
--- /dev/null
+++ b/usr/src/ucbcmd/mkstr/mkstr.xcl
@@ -0,0 +1,29 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+msgid "@(#)mkstr.c 1.8 90/07/06 SMI"
+msgid ""
+msgid "a"
+msgid "w"
+msgid "r"
+msgid "%d"
+msgid "\n"
diff --git a/usr/src/ucbcmd/plot/Makefile b/usr/src/ucbcmd/plot/Makefile
new file mode 100644
index 0000000000..38be88a3cf
--- /dev/null
+++ b/usr/src/ucbcmd/plot/Makefile
@@ -0,0 +1,226 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1989, 2001, 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+PROG= tek t4013 t300 t300s t450 aedplot bgplot dumbplot gigiplot \
+ hpplot hp7221plot implot atoplot plottoa vplot crtplot plot
+
+SUBDIRS= libplot
+
+DRVOBJ= driver.o
+VPLOTOBJ= vplot.o chrtab.o
+CRTOBJ= crtplot.o crtdriver.o
+ATOOBJ= atoplot.o
+TOAOBJ= plottoa.o
+
+OBJS= $(DRVOBJ) $(VPLOTOBJ) $(CRTOBJ) $(ATOOBJ) $(TOAOBJ)
+
+DRVSRC= $(DRVOBJ:%.o=%.c)
+VPLOTSRC= $(VPLOTOBJ:%.o=%.c)
+CRTSRC= $(CRTOBJ:%.o=%.c)
+ATOSRC= $(ATOOBJ:%.o=%.c)
+TOASRC= $(TOAOBJ:%.o=%.c)
+
+SRCS= $(DRVSRC) $(VPLOTSRC) $(CRTSRC) $(ATOSRC) $(TOASRC)
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+INC1 = $(ROOT)/usr/ucbinclude
+
+LDFLAGS += -L$(ROOT)/usr/ucblib
+
+LIBPLOT = ./libplot
+
+LIBS.DEF = -lucb
+LIBS.PLOT =
+LDLIBS += $(LIBS.PLOT) $(LIBS.DEF)
+
+#CPPFLAGS.master += -I$(INC1)
+CPPFLAGS = -I$(INC1) $(CPPFLAGS.master)
+
+clean:= TARGET= clean
+clobber:= TARGET= clobber
+
+.KEEP_STATE:
+
+all: $(PROG) debug
+
+tek:= LDFLAGS += -L$(LIBPLOT)
+tek:= LIBS.PLOT = -lm -lt4014
+tek: $(DRVOBJ) $(LIBPLOT)/libt4014.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+t4013:= LDFLAGS += -L$(LIBPLOT)
+t4013:= LIBS.PLOT = -lm -lt4013
+t4013: $(DRVOBJ) $(LIBPLOT)/libt4013.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+t300:= LDFLAGS += -L$(LIBPLOT)
+t300:= LIBS.PLOT = -lm -lt300
+t300: $(DRVOBJ) $(LIBPLOT)/libt300.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+t300s:= LDFLAGS += -L$(LIBPLOT)
+t300s:= LIBS.PLOT = -lm -lt300s
+t300s: $(DRVOBJ) $(LIBPLOT)/libt300s.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+t450:= LDFLAGS += -L$(LIBPLOT)
+t450:= LIBS.PLOT = -lm -lt450
+t450: $(DRVOBJ) $(LIBPLOT)/libt450.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+vplot: $(VPLOTOBJ)
+ $(SETRUNPATH) $(LINK.c) $(VPLOTOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+crtplot:= LDFLAGS += -L$(LIBPLOT)
+crtplot:= LIBS.DEF = -lcurses -ltermcap -lm -lucb
+crtplot: $(CRTOBJ)
+ $(SETRUNPATH) $(LINK.c) $(CRTOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+aedplot:= LDFLAGS += -L$(LIBPLOT)
+aedplot:= LIBS.PLOT = -laed
+aedplot: $(DRVOBJ) $(LIBPLOT)/libaed.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+bgplot:= LDFLAGS += -L$(LIBPLOT)
+bgplot:= LIBS.PLOT = -lm -lplotbg
+bgplot: $(DRVOBJ) $(LIBPLOT)/libplotbg.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+dumbplot:= LDFLAGS += -L$(LIBPLOT)
+dumbplot:= LIBS.DEF = -ltermcap -lm -lucb
+dumbplot:= LIBS.PLOT = -lm -ldumb
+dumbplot: $(DRVOBJ) $(LIBPLOT)/libdumb.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+gigiplot:= LDFLAGS += -L$(LIBPLOT)
+gigiplot:= LIBS.PLOT = -lm -lgigi
+gigiplot: $(DRVOBJ) $(LIBPLOT)/libgigi.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+hpplot:= LDFLAGS += -L$(LIBPLOT)
+hpplot:= LIBS.PLOT = -lm -lhp2648
+hpplot: $(DRVOBJ) $(LIBPLOT)/libhp2648.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+hp7221plot:= LDFLAGS += -L$(LIBPLOT)
+hp7221plot:= LIBS.PLOT = -lm -lhp7221
+hp7221plot: $(DRVOBJ) $(LIBPLOT)/libhp7221.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+implot:= LDFLAGS += -L$(LIBPLOT)
+implot:= LIBS.PLOT = -lm -limagen
+implot: $(DRVOBJ) $(LIBPLOT)/libimagen.a
+ $(SETRUNPATH) $(LINK.c) $(DRVOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+atoplot:= LDFLAGS += -L$(LIBPLOT)
+atoplot:= LIBS.PLOT = -lplot
+atoplot: $(ATOOBJ) $(LIBPLOT)/libplot.a
+ $(SETRUNPATH) $(LINK.c) $(ATOOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+plottoa: $(TOAOBJ)
+ $(SETRUNPATH) $(LINK.c) $(TOAOBJ) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+$(LIBPLOT)/libt300.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) t300
+
+$(LIBPLOT)/libt300s.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) t300s
+
+$(LIBPLOT)/libt450.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) t450
+
+$(LIBPLOT)/libt4014.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) t4014
+
+$(LIBPLOT)/libaed.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) aed
+
+$(LIBPLOT)/libplotbg.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) bitgraph
+
+$(LIBPLOT)/libdumb.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) dumb
+
+$(LIBPLOT)/libgigi.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) gigi
+
+$(LIBPLOT)/libhp2648.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) hp2648
+
+$(LIBPLOT)/libhp7221.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) hp7221
+
+$(LIBPLOT)/libimagen.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) imagen
+
+$(LIBPLOT)/libplot.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) plot
+
+$(LIBPLOT)/libt4013.a: FRC
+ cd $(LIBPLOT); pwd; $(MAKE) t4013
+
+install: all $(ROOTPROG)
+
+clean: $(SUBDIRS) clean_all
+
+clobber: $(SUBDIRS) clobber_all
+
+clean_all:
+ $(RM) $(OBJS)
+
+clobber_all:
+ $(RM) $(PROG)
+
+$(SUBDIRS): FRC
+ @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET)
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
+
+FRC:
+
diff --git a/usr/src/ucbcmd/plot/atoplot.c b/usr/src/ucbcmd/plot/atoplot.c
new file mode 100644
index 0000000000..70df691e6e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/atoplot.c
@@ -0,0 +1,181 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include <stdio.h>
+
+float deltx;
+float delty;
+
+char *mapLineType();
+
+main(argc,argv) char **argv; {
+ int std=1;
+ FILE *fin;
+
+ while(argc-- > 1) {
+ if(*argv[1] == '-')
+ switch(argv[1][1]) {
+ case 'l':
+ deltx = atoi(&argv[1][2]) - 1;
+ break;
+ case 'w':
+ delty = atoi(&argv[1][2]) - 1;
+ break;
+ }
+
+ else {
+ std = 0;
+ if ((fin = fopen(argv[1], "r")) == NULL) {
+ fprintf(stderr, "can't open %s\n", argv[1]);
+ exit(1);
+ }
+ fplt(fin);
+ fclose(fin);
+ }
+ argv++;
+ }
+ if (std)
+ fplt( stdin );
+ exit(0);
+ }
+
+
+fplt(fin) FILE *fin; {
+ int c;
+ char s[256];
+ int xi,yi,x0,y0,x1,y1,r,dx,n,i;
+ int pat[256];
+
+ openpl();
+ while((c=getc(fin)) != EOF){
+ switch(c){
+ case 'm':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ move(xi,yi);
+ break;
+ case 'l':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ line(x0,y0,x1,y1);
+ break;
+ case 't':
+ getstr(s,fin);
+ label(s);
+ break;
+ case 'e':
+ erase();
+ break;
+ case 'p':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ point(xi,yi);
+ break;
+ case 'n':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ cont(xi,yi);
+ break;
+ case 's':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ space(x0,y0,x1,y1);
+ break;
+ case 'a':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ arc(xi,yi,x0,y0,x1,y1);
+ break;
+ case 'c':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ r = getsi(fin);
+ circle(xi,yi,r);
+ break;
+ case 'f':
+ getstr(s,fin);
+ linemod( mapLineType(s) );
+ break;
+ case 'd':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ dx = getsi(fin);
+ n = getsi(fin);
+ for(i=0; i<n; i++)pat[i] = getsi(fin);
+ dot(xi,yi,dx,n,pat);
+ break;
+ }
+ /* scan to newline */
+ while( (c = getc( fin )) != '\n' ) {
+ if ( c == EOF ) {
+ break;
+ }
+ }
+ }
+ closepl();
+ }
+getsi(fin) FILE *fin; { /* get an integer stored in 2 ascii bytes. */
+ int i;
+
+ if ( fscanf(fin, " %d", & i) != 1 ) {
+ return(EOF);
+ }
+ return( i );
+}
+getstr(s,fin) char *s; FILE *fin; {
+ for( ; *s = getc(fin); s++)
+ if(*s == '\n')
+ break;
+ *s = '\0';
+}
+
+char *lineMap[] = {
+ "solid", /* line type 0 */
+ "solid", /* line type 1 */
+ "dotted", /* line type 2 */
+ "dotdashed", /* line type 3 */
+ "shortdashed", /* line type 4 */
+ "longdashed", /* line type 5 */
+ "dotlongdash", /* line type 6 */
+ "dotshortdash", /* line type 7 */
+ "dotdotdash", /* line type 8 */
+} ;
+
+char *
+mapLineType( cp )
+ char *cp;
+{
+ int i;
+
+ if ( sscanf(cp, "%d", &i) == 1 ) {
+ if ( i < 0 || i > sizeof(lineMap)/sizeof(char *) ) {
+ i = 1;
+ }
+ return( lineMap[i] );
+ }
+ else {
+ return( cp );
+ }
+}
diff --git a/usr/src/ucbcmd/plot/chrtab.c b/usr/src/ucbcmd/plot/chrtab.c
new file mode 100644
index 0000000000..9ae1e40e48
--- /dev/null
+++ b/usr/src/ucbcmd/plot/chrtab.c
@@ -0,0 +1,117 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+char chrtab[][16] = {
+0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, sp, */
+0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0010,0000,0000,0000,0000,0000, /*, !, */
+0024,0024,0024,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ", */
+0000,0000,0000,0044,0044,0176,0044,0044,0176,0044,0044,0000,0000,0000,0000,0000, /*, #, */
+0000,0010,0010,0010,0076,0101,0100,0076,0001,0101,0076,0010,0010,0000,0000,0000, /*, $, */
+0000,0000,0000,0141,0142,0004,0010,0010,0020,0043,0103,0000,0000,0000,0000,0000, /*, %, */
+0000,0000,0070,0104,0110,0060,0060,0111,0106,0106,0071,0000,0000,0000,0000,0000, /*, &, */
+0004,0010,0020,0040,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ', */
+0000,0004,0010,0020,0040,0040,0040,0040,0040,0040,0020,0010,0004,0000,0000,0000, /*, (, */
+0000,0040,0020,0010,0004,0004,0004,0004,0004,0004,0010,0020,0040,0000,0000,0000, /*, ), */
+0000,0000,0000,0010,0111,0052,0034,0177,0034,0052,0111,0010,0000,0000,0000,0000, /*, *, */
+0000,0000,0000,0000,0010,0010,0010,0177,0010,0010,0010,0000,0000,0000,0000,0000, /*, +, */
+0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0010,0020,0000,0000,0000, /*, ,, */
+0000,0000,0000,0000,0000,0000,0000,0176,0000,0000,0000,0000,0000,0000,0000,0000, /*, -, */
+0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0000,0000,0000,0000,0000, /*, ., */
+0000,0000,0001,0002,0004,0010,0010,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, /, */
+0000,0030,0044,0102,0102,0102,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 0, */
+0000,0010,0030,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, 1, */
+0000,0070,0104,0004,0004,0010,0020,0040,0100,0100,0174,0000,0000,0000,0000,0000, /*, 2, */
+0000,0176,0004,0004,0010,0014,0002,0002,0002,0104,0070,0000,0000,0000,0000,0000, /*, 3, */
+0000,0004,0014,0024,0044,0104,0176,0004,0004,0004,0004,0000,0000,0000,0000,0000, /*, 4, */
+0000,0174,0100,0100,0130,0144,0002,0002,0102,0044,0030,0000,0000,0000,0000,0000, /*, 5, */
+0000,0074,0102,0100,0130,0144,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 6, */
+0000,0176,0004,0004,0010,0010,0020,0020,0040,0040,0040,0000,0000,0000,0000,0000, /*, 7, */
+0000,0034,0042,0101,0042,0076,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, 8, */
+0000,0034,0042,0101,0101,0101,0043,0036,0004,0010,0020,0040,0000,0000,0000,0000, /*, 9, */
+0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0000,0000,0000,0000,0000, /*, :, */
+0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0020,0040,0000,0000,0000, /*, ;, */
+0002,0004,0010,0020,0040,0100,0040,0020,0010,0004,0002,0000,0000,0000,0000,0000, /*, <, */
+0000,0000,0000,0000,0177,0000,0177,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, =, */
+0100,0040,0020,0010,0004,0002,0004,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, >, */
+0000,0030,0044,0102,0001,0002,0004,0010,0010,0000,0010,0000,0000,0000,0000,0000, /*, ?, */
+0000,0074,0102,0101,0115,0123,0121,0121,0121,0111,0046,0000,0000,0000,0000,0000, /*, @, */
+0000,0010,0024,0042,0101,0101,0177,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, A, */
+0000,0176,0101,0101,0101,0176,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, B, */
+0000,0076,0101,0100,0100,0100,0100,0100,0100,0101,0076,0000,0000,0000,0000,0000, /*, C, */
+0000,0176,0101,0101,0101,0101,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, D, */
+0000,0176,0100,0100,0100,0170,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, E, */
+0000,0177,0100,0100,0100,0174,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, F, */
+0000,0076,0101,0100,0100,0117,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, G, */
+0000,0101,0101,0101,0101,0176,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, H, */
+0000,0034,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, I, */
+0000,0016,0004,0004,0004,0004,0004,0004,0104,0104,0070,0000,0000,0000,0000,0000, /*, J, */
+0000,0101,0102,0104,0110,0120,0160,0110,0104,0102,0101,0000,0000,0000,0000,0000, /*, K, */
+0000,0100,0100,0100,0100,0100,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, L, */
+0000,0101,0143,0125,0111,0101,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, M, */
+0000,0101,0141,0121,0111,0105,0103,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, N, */
+0000,0076,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, O, */
+0000,0176,0101,0101,0101,0176,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, P, */
+0000,0076,0101,0101,0101,0101,0101,0101,0131,0105,0076,0002,0001,0000,0000,0000, /*, Q, */
+0000,0176,0101,0101,0101,0176,0104,0102,0101,0101,0101,0000,0000,0000,0000,0000, /*, R, */
+0000,0076,0101,0100,0100,0076,0001,0001,0001,0101,0076,0000,0000,0000,0000,0000, /*, S, */
+0000,0177,0010,0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, T, */
+0000,0101,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, U, */
+0000,0101,0101,0101,0101,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, V, */
+0000,0101,0101,0101,0101,0111,0111,0125,0143,0101,0101,0000,0000,0000,0000,0000, /*, W, */
+0000,0101,0101,0042,0024,0010,0024,0042,0101,0101,0101,0000,0000,0000,0000,0000, /*, X, */
+0000,0101,0042,0024,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, Y, */
+0000,0177,0001,0002,0004,0010,0020,0040,0100,0100,0177,0000,0000,0000,0000,0000, /*, Z, */
+0000,0034,0020,0020,0020,0020,0020,0020,0020,0020,0020,0034,0000,0000,0000,0000, /*, [, */
+0000,0000,0100,0040,0020,0010,0010,0010,0004,0002,0001,0000,0000,0000,0000,0000, /*, , \, */
+0000,0070,0010,0010,0010,0010,0010,0010,0010,0010,0010,0070,0000,0000,0000,0000, /*, ], */
+0010,0024,0042,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ^, */
+0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,(char)0377,0000,0000, /*, _, */
+0040,0020,0010,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, `, */
+0000,0000,0000,0000,0000,0074,0002,0076,0102,0102,0076,0000,0000,0000,0000,0000, /*, a, */
+0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0174,0000,0000,0000,0000,0000, /*, b, */
+0000,0000,0000,0000,0000,0074,0102,0100,0100,0102,0074,0000,0000,0000,0000,0000, /*, c, */
+0002,0002,0002,0002,0002,0076,0102,0102,0102,0102,0076,0000,0000,0000,0000,0000, /*, d, */
+0000,0000,0000,0000,0000,0074,0102,0174,0100,0102,0074,0000,0000,0000,0000,0000, /*, e, */
+0000,0016,0020,0020,0020,0176,0020,0020,0020,0020,0020,0000,0000,0000,0000,0000, /*, f, */
+0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0102,0076,0000, /*, g, */
+0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, h, */
+0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, i, */
+0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0010,0010,0010,0050,0020,0000, /*, j, */
+0000,0100,0100,0100,0100,0106,0110,0120,0160,0110,0106,0000,0000,0000,0000,0000, /*, k, */
+0000,0030,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, l, */
+0000,0000,0000,0000,0000,0166,0111,0111,0111,0111,0111,0000,0000,0000,0000,0000, /*, m, */
+0000,0000,0000,0000,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, n, */
+0000,0000,0000,0000,0000,0074,0102,0102,0102,0102,0074,0000,0000,0000,0000,0000, /*, o, */
+0000,0000,0000,0000,0000,0174,0102,0102,0102,0102,0174,0100,0100,0100,0100,0000, /*, p, */
+0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0002,0002,0000, /*, q, */
+0000,0000,0000,0000,0000,0134,0142,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, r, */
+0000,0000,0000,0000,0000,0076,0100,0074,0002,0102,0074,0000,0000,0000,0000,0000, /*, s, */
+0000,0020,0020,0020,0020,0176,0020,0020,0020,0020,0014,0000,0000,0000,0000,0000, /*, t, */
+0000,0000,0000,0000,0000,0102,0102,0102,0102,0102,0075,0000,0000,0000,0000,0000, /*, u, */
+0000,0000,0000,0000,0000,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, v, */
+0000,0000,0000,0000,0000,0111,0111,0111,0111,0111,0066,0000,0000,0000,0000,0000, /*, w, */
+0000,0000,0000,0000,0000,0102,0044,0030,0030,0044,0102,0000,0000,0000,0000,0000, /*, x, */
+0000,0000,0000,0000,0000,0102,0102,0102,0042,0024,0010,0020,0040,0100,0000,0000, /*, y, */
+0000,0000,0000,0000,0000,0176,0004,0010,0020,0040,0176,0000,0000,0000,0000,0000, /*, z, */
+0000,0014,0020,0020,0020,0020,0040,0020,0020,0020,0020,0014,0000,0000,0000,0000, /*, {, */
+0000,0010,0010,0010,0010,0000,0000,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, |, */
+0000,0030,0010,0010,0010,0010,0004,0010,0010,0010,0010,0030,0000,0000,0000,0000, /*, }, */
+0020,0052,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ~, */
+0000,0176,0176,0176,0176,0176,0176,0176,0176,0176,0176,0000,0000,0000,0000,0000, /*, del, */
+};
diff --git a/usr/src/ucbcmd/plot/crtdriver.c b/usr/src/ucbcmd/plot/crtdriver.c
new file mode 100644
index 0000000000..8159e55754
--- /dev/null
+++ b/usr/src/ucbcmd/plot/crtdriver.c
@@ -0,0 +1,152 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+This driver is used with crtplot.c.
+It is essentially the same driver as the one in /usr/src/cmd/plot.
+Unfortunately, the curses library has some of the same names as does
+as the functions that the driver calls. These have been changed.
+
+Also, one of the commands has been removed since they don't make sense
+for crt's.
+*/
+
+
+#include <stdio.h>
+
+float deltx;
+float delty;
+
+main(argc,argv) char **argv; {
+ int std=1;
+ FILE *fin;
+
+ while(argc-- > 1) {
+ if(*argv[1] == '-')
+ switch(argv[1][1]) {
+ case 'l':
+ deltx = atoi(&argv[1][2]) - 1;
+ break;
+ case 'w':
+ delty = atoi(&argv[1][2]) - 1;
+ break;
+ }
+
+ else {
+ std = 0;
+ if ((fin = fopen(argv[1], "r")) == NULL) {
+ printw("can't open %s\n", argv[1]);
+ exit(1);
+ }
+ fplt(fin);
+ }
+ argv++;
+ }
+ if (std)
+ fplt( stdin );
+
+ exit(0);
+ }
+
+fplt(fin) FILE *fin; {
+ int c;
+ char s[256];
+ int xi,yi,x0,y0,x1,y1,r/*,dx,n,i*/;
+ /*int pat[256];*/
+
+ openpl();
+ while((c=getc(fin)) != EOF){
+ switch(c){
+ case 'm':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ plot_move(xi,yi);
+ break;
+ case 'l':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ line(x0,y0,x1,y1);
+ break;
+ case 't':
+ getstr(s,fin);
+ label(s);
+ break;
+ case 'e':
+ plot_erase();
+ break;
+ case 'p':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ point(xi,yi);
+ break;
+ case 'n':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ cont(xi,yi);
+ break;
+ case 's':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ space(x0,y0,x1,y1);
+ break;
+ case 'a':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ arc(xi,yi,x0,y0,x1,y1);
+ break;
+ case 'c':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ r = getsi(fin);
+ circle(xi,yi,r);
+ break;
+ case 'f':
+ getstr(s,fin);
+ linemod(s);
+ break;
+ default:
+ fprintf(stderr, "Unknown command %c (%o)\n", c, c);
+ break;
+ }
+ }
+ closepl();
+ }
+getsi(fin) FILE *fin; { /* get an integer stored in 2 ascii bytes. */
+ short a, b;
+ if((b = getc(fin)) == EOF)
+ return(EOF);
+ if((a = getc(fin)) == EOF)
+ return(EOF);
+ a = a<<8;
+ return(a|b);
+}
+getstr(s,fin) char *s; FILE *fin; {
+ for( ; *s = getc(fin); s++)
+ if(*s == '\n')
+ break;
+ *s = '\0';
+}
diff --git a/usr/src/ucbcmd/plot/crtplot.c b/usr/src/ucbcmd/plot/crtplot.c
new file mode 100644
index 0000000000..5eeefb2f65
--- /dev/null
+++ b/usr/src/ucbcmd/plot/crtplot.c
@@ -0,0 +1,305 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+This plotting routine interprets plot commands and outputs them onto
+intelligent terminals (ie, terminals with clear screen and cursor
+addressability. It uses the curses library. It should be compiled
+as follows:
+ cc crtdriver.c crtplot.c -lcurses -ltermcap -lm
+Note: This requires as slightly modified driver from the standard driver
+because some function names conflicted with the curses library.
+(That's what you get when you have a flat name space!)
+*/
+
+
+#include <curses.h>
+#include <math.h>
+#include <signal.h>
+
+/* These map from plot routine coordinates to screen coordinates. */
+#define scaleX(x) (int) ((x-lowX)*rangeX + 0.5)
+#define scaleY(y) (int) (LINES-0.5 - ((y-lowY)*rangeY))
+
+#define plot_movech(y, x, ch) { plot_move(x, y); plot_addch(ch); }
+
+
+static double lowX, rangeX; /* min and range of x */
+static double lowY, rangeY; /* min and range of y */
+static int lastX, lastY; /* last point plotted */
+
+
+char *getenv();
+/* This routine just moves the cursor. */
+screen_move(y, x)
+int x,y;
+{
+ /* must check for automatic wrap at last col */
+ if (!AM || (y < LINES -1) || (x < COLS -1)) {
+ mvcur(lastY, lastX, y, x);
+ lastY = y;
+ lastX = x;
+ }
+}
+
+
+/* This routine assumes the cursor is positioned correctly. */
+plot_addch(ch)
+char ch;
+{
+ putchar(ch);
+ if (++lastX >= COLS) {
+ if (AM) {
+ lastX = 0;
+ lastY++;
+ } else {
+ lastX = COLS - 1;
+ }
+ }
+}
+
+
+
+
+/* See the curses manual for what is been done and why. */
+openpl()
+{
+char *sp;
+void closepl();
+
+gettmode();
+if (sp=getenv("TERM"))
+ setterm(sp);
+signal(SIGINT, closepl);
+
+}
+
+
+
+
+void closepl()
+{
+signal(SIGINT, SIG_IGN);
+/* Leave cursor at top of screen. */
+mvcur(LINES-1, COLS-1, 0, 0);
+endwin();
+exit(0);
+}
+
+
+
+plot_move(x,y)
+int x, y;
+{
+screen_move(scaleY(y), scaleX(x));
+}
+
+
+
+line(x0, y0, x1, y1)
+int x0, y0, x1, y1;
+{
+plot_movech(y0, x0, '*');
+dda_line('*', scaleX(x0), scaleY(y0), scaleX(x1), scaleY(y1));
+}
+
+label(str)
+char *str;
+{
+ reg i, length;
+ int strlen();
+
+ if ( (length=strlen(str)) > (COLS-lastX) )
+ length = COLS - lastX;
+ for (i=0; i<length; ++i)
+ plot_addch(str[i]);
+}
+
+plot_erase()
+{
+int _putchar();
+/*
+Some of these functions probably belong in openpl(). However, if the
+input is being typed in, putting them in openpl would not work
+since "noecho", etc would prevent (sort of) input. Notice that
+the driver calls openpl before doing anything. This is actually
+wrong, but it is what whoever originally wrote the driver decided
+to do. (openpl() in libplot does nothing -- that is the main problem!)
+*/
+_puts(TI);
+_puts(VS);
+
+noecho();
+nonl();
+tputs(CL, LINES, _putchar);
+mvcur(0, COLS-1, LINES-1, 0);
+lastX = 0;
+lastY = LINES-1;
+}
+
+
+point(x, y)
+int x,y;
+{
+plot_movech(y, x, '*');
+}
+
+
+cont(x, y)
+int x,y;
+{
+dda_line('*', lastX-1, lastY, scaleX(x), scaleY(y));
+}
+
+
+space(x0, y0, x1, y1)
+int x0, y0, x1, y1;
+{
+lowX = (double) x0;
+lowY = (double) y0;
+rangeX = COLS/(double) (x1 - x0);
+rangeY = LINES/(double) (y1 - y0);
+}
+
+
+linemod(string)
+char *string;
+{
+}
+
+
+
+/* See Neuman & Sproul for explanation and rationale. */
+/* Does not plot first point -- assumed that it is already plotted */
+dda_line(ch, x0, y0, x1, y1)
+char ch;
+int x0, y0, x1, y1; /* already transformed to screen coords */
+{
+ int length, i;
+ double deltaX, deltaY;
+ double x, y;
+ double floor();
+ int abs();
+
+length = abs(x1 - x0);
+if (abs(y1 -y0) > length)
+ length = abs(y1 - y0);
+
+if (length == 0)
+ return;
+
+deltaX = (double) (x1 - x0)/(double) length;
+deltaY = (double) (y1 - y0)/(double) length;
+
+x = (double) x0 + 0.5;
+y = (double) y0 + 0.5;
+
+for (i=0; i < length; ++i)
+ {
+ x += deltaX;
+ y += deltaY;
+ screen_move((int) floor(y), (int) floor(x));
+ plot_addch(ch);
+ }
+}
+
+
+circle (xc,yc,r)
+int xc,yc,r;
+{
+ arc(xc,yc, xc+r,yc, xc-r,yc);
+ arc(xc,yc, xc-r,yc, xc+r,yc);
+}
+
+
+/* should include test for equality? */
+#define side(x,y) (a*(x)+b*(y)+c > 0.0 ? 1 : -1)
+
+arc(xc,yc,xbeg,ybeg,xend,yend)
+int xc,yc,xbeg,ybeg,xend,yend;
+{
+ double r, radius, costheta, sintheta;
+ double a, b, c, x, y, tempX;
+ int right_side;
+
+ xbeg -= xc; ybeg -= yc;
+ xend -= xc; yend -= yc;
+
+ /* probably should check that arc is truely circular */
+ /* Note: r is in screen coordinates. */
+ r = sqrt( rangeX*rangeX*xbeg*xbeg + rangeY*rangeY*ybeg*ybeg);
+
+ /*
+ This method is reasonably efficient, clean, and clever.
+ The easy part is generating the next point on the arc. This is
+ done by rotating the points by the angle theta. Theta is chosen
+ so that no rotation will cause more than one pixel of a move.
+ This corresponds to a triangle having 'x side' of r and 'y side' of 1.
+ The rotation is done (way) below inside the loop.
+ */
+ if (r <= 1.0) {
+ /* radius is mapped to length < 1*/
+ point(xc,yc);
+ return;
+ }
+
+ radius = sqrt(r*r + 1.0);
+ sintheta = 1.0/radius;
+ costheta = r/radius;
+
+ /*
+ The hard part of drawing an arc is figuring out when to stop.
+ This method works by drawing the line from the beginning point
+ to the ending point. This splits the plane in half, with the
+ arc that we wish to draw on one side of the line. If we evaluate
+ side(x,y) = a*x + b*y + c, then all of the points on one side of the
+ line will result in side being positive, and all the points on the
+ other side of the line will result in side being negative.
+
+ We want to draw the arc in a counter-clockwise direction, so we
+ must find out what the sign of "side" is for a point which is to the
+ "right" of a line drawn from "beg" to "end". A point which must lie
+ on the right is [xbeg + (yend-ybeg), ybeg - (xend-xbeg)]. (This
+ point is perpendicular to the line at "beg").
+
+ Thus, we compute "side" of the above point, and then compare the
+ sign of side for each new point with the sign of the above point.
+ When they are different, we terminate the loop.
+ */
+
+ a = (double) (yend - ybeg);
+ b = (double) (xend - xbeg);
+ c = (double) (yend*xbeg - xend*ybeg);
+ right_side = side(xbeg + (yend-ybeg),
+ ybeg - (xend-xbeg) );
+
+ x = xbeg;
+ y = ybeg;
+ plot_move(xbeg+xc, ybeg+yc);
+ do {
+ dda_line('*',lastX-1, lastY, scaleX(xc + x), scaleY(yc + y ));
+ /*
+ screen_move( scaleY(yc + y), scaleX(xc + x) );
+ plot_addch('*');
+ */
+ tempX = x;
+ x = x*costheta - y*sintheta;
+ y = tempX*sintheta + y*costheta;
+ } while( side(x,y) == right_side );
+}
diff --git a/usr/src/ucbcmd/plot/debug.c b/usr/src/ucbcmd/plot/debug.c
new file mode 100644
index 0000000000..8a89258de5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/debug.c
@@ -0,0 +1,140 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+
+float deltx;
+float delty;
+
+main(argc,argv) char **argv; {
+ int std=1;
+ FILE *fin;
+
+ while(argc-- > 1) {
+ if(*argv[1] == '-')
+ switch(argv[1][1]) {
+ case 'l':
+ deltx = atoi(&argv[1][2]) - 1;
+ break;
+ case 'w':
+ delty = atoi(&argv[1][2]) - 1;
+ break;
+ }
+
+ else {
+ std = 0;
+ if ((fin = fopen(argv[1], "r")) == NULL) {
+ fprintf(stderr, "can't open %s\n", argv[1]);
+ exit(1);
+ }
+ fplt(fin);
+ }
+ argv++;
+ }
+ if (std)
+ fplt( stdin );
+ exit(0);
+ }
+
+
+fplt(fin) FILE *fin; {
+ int c;
+ char s[256];
+ int xi,yi,x0,y0,x1,y1,r/*,dx,n,i*/;
+
+ printf("openpl\n");
+ while((c=getc(fin)) != EOF){
+ switch(c){
+ case 'm':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ printf("move %d %d\n", xi, yi);
+ break;
+ case 'l':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ printf("line %d %d %d %d\n", x0, y0, x1, y1);
+ break;
+ case 't':
+ getstr(s,fin);
+ printf("label %s\n", s);
+ break;
+ case 'e':
+ printf("erase\n");
+ break;
+ case 'p':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ printf("point %d %d\n", xi, yi);
+ break;
+ case 'n':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ printf("continue %d %d\n", xi, yi);
+ break;
+ case 's':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ printf("space %d %d %d %d\n", x0, y0, x1, y1);
+ break;
+ case 'a':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ printf("arc\n");
+ break;
+ case 'c':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ r = getsi(fin);
+ printf("circle\n");
+ break;
+ case 'f':
+ getstr(s,fin);
+ printf("linemod %s\n", s);
+ break;
+ default:
+ fprintf(stderr, "Unknown command %c (%o)\n", c, c);
+ break;
+ }
+ }
+ printf("closepl\n");
+ }
+getsi(fin) FILE *fin; { /* get an integer stored in 2 ascii bytes. */
+ short a, b;
+ if((b = getc(fin)) == EOF)
+ return(EOF);
+ if((a = getc(fin)) == EOF)
+ return(EOF);
+ a = a<<8;
+ return(a|b);
+}
+getstr(s,fin) char *s; FILE *fin; {
+ for( ; *s = getc(fin); s++)
+ if(*s == '\n')
+ break;
+ *s = '\0';
+}
diff --git a/usr/src/ucbcmd/plot/driver.c b/usr/src/ucbcmd/plot/driver.c
new file mode 100644
index 0000000000..5c912e839f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/driver.c
@@ -0,0 +1,168 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+
+float deltx;
+float delty;
+int PlotRes;
+
+main(argc,argv)
+ int argc;
+ char *argv[];
+{
+ int std = 1;
+ char *progname;
+ FILE *fin;
+
+ progname = argv[0];
+ for (argc--, argv++; argc > 0; argc--, argv++) {
+ if (argv[0][0] == '-') {
+ switch (argv[0][1]) {
+ case 'l':
+ deltx = atoi(&argv[0][2]) - 1;
+ break;
+ case 'w':
+ delty = atoi(&argv[0][2]) - 1;
+ break;
+ case 'r':
+ PlotRes = atoi(&argv[0][2]);
+ break;
+ }
+ continue;
+ }
+ std = 0;
+ fin = fopen(argv[0], "r");
+ if (fin == NULL) {
+ fprintf(stderr, "%s: can't open %s\n", progname,
+ argv[0]);
+ exit(1);
+ }
+ fplt(fin);
+ fclose(fin);
+ }
+ if (std)
+ fplt(stdin);
+ exit(0);
+}
+
+fplt(fin)
+ FILE *fin;
+{
+ register int c;
+ char s[256];
+ int xi,yi,x0,y0,x1,y1,r,dx,n,i;
+ int pat[256];
+
+ openpl();
+ while((c = getc(fin)) != EOF) {
+ switch(c) {
+ case 'm':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ move(xi,yi);
+ break;
+ case 'l':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ line(x0,y0,x1,y1);
+ break;
+ case 't':
+ getstr(s,fin);
+ label(s);
+ break;
+ case 'e':
+ erase();
+ break;
+ case 'p':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ point(xi,yi);
+ break;
+ case 'n':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ cont(xi,yi);
+ break;
+ case 's':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ space(x0,y0,x1,y1);
+ break;
+ case 'a':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ arc(xi,yi,x0,y0,x1,y1);
+ break;
+ case 'c':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ r = getsi(fin);
+ circle(xi,yi,r);
+ break;
+ case 'f':
+ getstr(s,fin);
+ linemod(s);
+ break;
+ case 'd':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ dx = getsi(fin);
+ n = getsi(fin);
+ for(i=0; i<n; i++)
+ pat[i] = getsi(fin);
+ dot(xi,yi,dx,n,pat);
+ break;
+ }
+ }
+ closepl();
+}
+
+/* get an integer stored in 2 ascii bytes. */
+getsi(fin)
+ register FILE *fin;
+{
+ short a, b;
+
+ if((b = getc(fin)) == EOF)
+ return(EOF);
+ if((a = getc(fin)) == EOF)
+ return(EOF);
+ a = a<<8;
+ return(a|b);
+}
+
+getstr(s, fin)
+ register char *s;
+ register FILE *fin;
+{
+
+ for( ; *s = getc(fin); s++)
+ if(*s == '\n')
+ break;
+ *s = '\0';
+}
diff --git a/usr/src/ucbcmd/plot/libplot/Makefile b/usr/src/ucbcmd/plot/libplot/Makefile
new file mode 100644
index 0000000000..4e81560182
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/Makefile
@@ -0,0 +1,49 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+# include global definitions
+include ../../../Makefile.master
+
+SUBDIRS= aed bitgraph dumb gigi hp2648 hp7221 imagen plot \
+ t300 t300s t4013 t4014 t450
+
+all:= TARGET= all
+clean:= TARGET= clean
+clobber:= TARGET= clobber
+install:= TARGET= install
+lint:= TARGET= lint
+
+.KEEP_STATE:
+all clean clobber lint: $(SUBDIRS)
+
+install:
+
+$(SUBDIRS): FRC
+ @cd $@; pwd; $(MAKE) $(TARGET)
+
+
+FRC:
+
diff --git a/usr/src/ucbcmd/plot/libplot/aed/Makefile b/usr/src/ucbcmd/plot/libplot/aed/Makefile
new file mode 100644
index 0000000000..42e1f4b9e1
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/Makefile
@@ -0,0 +1,54 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libaed.a
+
+OBJECTS = arc.o box.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+# TXTS allows the AT&T makefile to be bootstrapped into the NSE.
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/aed/aed.h b/usr/src/ucbcmd/plot/libplot/aed/aed.h
new file mode 100644
index 0000000000..fc1a312ae2
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/aed.h
@@ -0,0 +1,36 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Displays plot files on an AED512 graphics terminal.
+ */
+
+#include <stdio.h>
+#include <sgtty.h>
+
+extern char dbuf[BUFSIZ]; /* Used to buffer display characters */
+extern struct sgttyb sgttyb; /* Used to save terminal control bits */
+extern curx, cury; /* Current screen position */
+extern int xbot, ybot; /* Coordinates of screen lower-left corner */
+extern int scale; /* The number of pixels per 2**12 units
+ * of world coordinates.
+ */
+
+/* The following variables describe the screen. */
+
+#define GRXMAX 511 /* Maximum x-coordinate of screen */
+#define GRYMAX 482 /* Maximum y-coordinate of screen */
diff --git a/usr/src/ucbcmd/plot/libplot/aed/arc.c b/usr/src/ucbcmd/plot/libplot/aed/arc.c
new file mode 100644
index 0000000000..c8d300492b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/arc.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+arc(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/box.c b/usr/src/ucbcmd/plot/libplot/aed/box.c
new file mode 100644
index 0000000000..dce4c8281b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/circle.c b/usr/src/ucbcmd/plot/libplot/aed/circle.c
new file mode 100644
index 0000000000..a622681905
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/circle.c
@@ -0,0 +1,41 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * Circle draws a circle.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * A circle of radius r is drawn at (x,y).
+ *---------------------------------------------------------
+ */
+circle(x, y, r)
+int x, y, r;
+{
+ char buf[3];
+ setcolor("01");
+ putc('Q', stdout);
+ outxy20(x, y);
+ putc('O', stdout);
+ chex((r*scale)>>12, buf, 2);
+ fputs(buf, stdout);
+ (void) fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/close.c b/usr/src/ucbcmd/plot/libplot/aed/close.c
new file mode 100644
index 0000000000..468d4a3177
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/close.c
@@ -0,0 +1,36 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * Closepl does whatever is necessary to reset the characteristics
+ * of the AED512 after the program is finished.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * The graphics display modes are reset.
+ *---------------------------------------------------------
+ */
+closepl()
+{
+ fputs("Q00204\6", stdout);
+ (void) fflush(stdout);
+ (void) stty(fileno(stdout), &sgttyb);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/cont.c b/usr/src/ucbcmd/plot/libplot/aed/cont.c
new file mode 100644
index 0000000000..0d37692198
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/cont.c
@@ -0,0 +1,32 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * Cont plots a line between (curx, cury) and (x, y).
+ *
+ * Results: None.
+ * Side Effects: As above.
+ *---------------------------------------------------------
+ */
+cont(x, y)
+int x, y;
+{
+ line(curx, cury, x, y);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/dot.c b/usr/src/ucbcmd/plot/libplot/aed/dot.c
new file mode 100644
index 0000000000..a0d3dcca35
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/erase.c b/usr/src/ucbcmd/plot/libplot/aed/erase.c
new file mode 100644
index 0000000000..bdcd5172f6
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/erase.c
@@ -0,0 +1,36 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * This routine erases the screen.
+ *
+ * Results: None.
+ * Side Effects: The screen is cleared.
+ *---------------------------------------------------------
+ */
+erase()
+{
+ setcolor("FF");
+ putc('\14', stdout);
+ putc('\33', stdout);
+ putc('Q', stdout);
+ outxy20(curx, cury);
+ (void) fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/label.c b/usr/src/ucbcmd/plot/libplot/aed/label.c
new file mode 100644
index 0000000000..78b55bfecc
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/label.c
@@ -0,0 +1,43 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * This routine places a label starting at the current
+ * position.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * The string indicated by s starting at (curx, cury).
+ * The current position is updated accordingly.
+ *---------------------------------------------------------
+ */
+label(s)
+char *s;
+{
+ setcolor("02");
+ putc('Q', stdout);
+ outxy20(curx + (4096/scale), cury + (4096/scale));
+ putc('\6', stdout);
+ fputs(s, stdout);
+ putc('\33', stdout);
+ (void) fflush(stdout);
+ curx += ((6*4096*strlen(s)) + 4000)/scale;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/line.c b/usr/src/ucbcmd/plot/libplot/aed/line.c
new file mode 100644
index 0000000000..f1dbe93bf2
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/line.c
@@ -0,0 +1,34 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * Line draws a line between two points.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * A line is drawn on the screen between (x1, y1) and (x2, y2).
+ *---------------------------------------------------------
+ */
+line(x1, y1, x2, y2)
+int x1, y1, x2, y2;
+{
+ setcolor("01");
+ putc('Q', stdout);
+ outxy20(x1, y1);
+ putc('A', stdout);
+ outxy20(x2, y2);
+ (void) fflush(stdout);
+ curx = x2;
+ cury = y2;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/linemod.c b/usr/src/ucbcmd/plot/libplot/aed/linemod.c
new file mode 100644
index 0000000000..b081ceaa17
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/linemod.c
@@ -0,0 +1,45 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * Linemod sets the current line drawing style.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * The AED line style is set based on string s which
+ * must be one of "dotted", "solid", "longdashed", "shortdashed",
+ * or "dotdashed". If s isn't recognized, then "solid" is used.
+ *---------------------------------------------------------
+ */
+linemod(s)
+char *s;
+{
+ if (strcmp(s, "dotted") == 0)
+ fputs("1AAFF", stdout);
+ else if (strcmp(s, "longdashed") == 0)
+ fputs("1F055", stdout);
+ else if (strcmp(s, "shortdashed") == 0)
+ fputs("1F0FF", stdout);
+ else if (strcmp(s, "dotdashed") == 0)
+ fputs("1E4FF", stdout);
+ else fputs("1FFFF", stdout);
+ (void) fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/move.c b/usr/src/ucbcmd/plot/libplot/aed/move.c
new file mode 100644
index 0000000000..393d6f153c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/move.c
@@ -0,0 +1,33 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * This routine moves the current point to (x,y).
+ *
+ * Results: None.
+ * Side Effects: As above.
+ *---------------------------------------------------------
+ */
+move(x, y)
+int x, y;
+{
+ curx = x;
+ cury = y;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/open.c b/usr/src/ucbcmd/plot/libplot/aed/open.c
new file mode 100644
index 0000000000..6bbdc8befc
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/open.c
@@ -0,0 +1,88 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+/*
+ * Displays plot files on a AED512 graphics terminal.
+ */
+
+#include "aed.h"
+
+char dbuf[BUFSIZ]; /* Used to buffer display characters */
+struct sgttyb sgttyb; /* Used to save terminal control bits */
+int curx, cury; /* Current screen position */
+int xbot, ybot; /* Coordinates of screen lower-left corner */
+int scale; /* The number of pixels per 2**12 units
+ * of world coordinates.
+ */
+
+/*
+ * The following is the color map, containing reg, green, and blue
+ * values for color locations 0 and 1.
+ */
+
+static int colors[] = {200, 200, 200, 0, 0, 125, 125, 0, 0, 125, 0, 0};
+
+/*---------------------------------------------------------
+ * Openpl initializes the graphics display and clears its screen.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * The display is re-initialized and the file is remembered for
+ * use in all subsequent calls to this module. The display's
+ * color map is reset. The display is put into raw mode, but
+ * the previous mode bits are saved.
+ *
+ * Errors: None.
+ *---------------------------------------------------------
+ */
+openpl()
+{
+ int flags, *p, i;
+ char dum[4];
+
+ /* First, grab up the display modes, then reset them to put it
+ * into cooked mode. Also, lock the terminal.
+ */
+
+ (void) gtty(fileno(stdout), &sgttyb);
+ flags = sgttyb.sg_flags;
+ sgttyb.sg_flags = (sgttyb.sg_flags & ~(RAW)) | EVENP | ODDP;
+ (void) stty(fileno(stdout), &sgttyb);
+ sgttyb.sg_flags = flags;
+
+ /* Save the file pointer around for later use, then output an
+ * initialization string to the display. The initialization
+ * string resets the terminal, sets formats, clears the display,
+ * initializes the read and write masks, and sets the color map.
+ */
+
+ setbuf(stdout, dbuf);
+ fputs("\33\33G1HHHN[00LFFCFFMFFFFFFFF", stdout);
+ fputs("K0004", stdout);
+ p = colors;
+ for (i=0; i<12; i++)
+ {
+ chex(*p++, dum, 2);
+ fputs(dum, stdout);
+ }
+ fputs("^15060AL", stdout);
+ scale = 1<<12;
+ curx = cury = xbot = ybot = 0;
+ (void) fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/point.c b/usr/src/ucbcmd/plot/libplot/aed/point.c
new file mode 100644
index 0000000000..7b8fdb2e30
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/point.c
@@ -0,0 +1,41 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * This routine plots a single point.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * A single point is displayed on the screen.
+ * The point is made the current point.
+ *---------------------------------------------------------
+ */
+point(x, y)
+int x, y;
+{
+ setcolor("01");
+ putc('Q', stdout);
+ outxy20(x, y);
+ fputs("O01", stdout);
+ (void) fflush(stdout);
+ curx = x;
+ cury = y;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/space.c b/usr/src/ucbcmd/plot/libplot/aed/space.c
new file mode 100644
index 0000000000..1bbc37b7e5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/space.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*---------------------------------------------------------
+ * Space sets up the world-to-screen transformation so
+ * that the rectangular area described by (x0, y0) and
+ * (x1, y1) will all be on-screen.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * Our own variables scale, xbot, and ybot are changed.
+ *---------------------------------------------------------
+ */
+space(x0, y0, x1, y1)
+int x0, y0, x1, y1;
+{
+ int xscale, yscale, xsize, ysize;
+ xscale = (GRXMAX<<12)/(x1-x0);
+ yscale = (GRYMAX<<12)/(y1-y0);
+ if (xscale > yscale) scale = yscale;
+ else scale = xscale;
+ scale = (scale*9)/10 - 1;
+ if (scale<1) scale = 1;
+ xsize = (2048*GRXMAX)/scale + 1;
+ xbot = (x1+x0)/2 - xsize;
+ ysize = (2048*GRYMAX)/scale + 1;
+ ybot = (y1+y0)/2 - ysize;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/aed/subr.c b/usr/src/ucbcmd/plot/libplot/aed/subr.c
new file mode 100644
index 0000000000..57ea924424
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/aed/subr.c
@@ -0,0 +1,105 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+
+#include "aed.h"
+
+/*
+ * The following table is used to convert numbers to hex. We cannot use
+ * standard C library conversion because it generates lower case letters
+ * which are bad news to the AED512.
+ */
+
+static char hex[] = "0123456789ABCDEF";
+
+/*---------------------------------------------------------
+ * This is a local routine that converts an integer to a string
+ * of hexadecimal characters.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * The string contains the value of the low-order nchars 4-bit chunks
+ * of val, as represented in hexadecimal. String is zero-filled.
+ *---------------------------------------------------------
+ */
+chex(val, string, nchars)
+int val; /* Integer value to be converted. */
+char *string; /* Pointer to area for converted result. */
+int nchars; /* Number of characters to be converted. */
+{
+ string = &(string[nchars]);
+ *string = '\0';
+ for (; nchars>0 ; nchars--)
+ {
+ *(--string) = hex[val & 017];
+ val >>= 4;
+ }
+}
+
+/*---------------------------------------------------------
+ * This local routine outputs an x-y coordinate pair in the standard
+ * format required by the AED display.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * Characters are output to the AED512 in the standard way required
+ * for values indicated by "xy20" in the user manual.
+ *
+ * Errors: None.
+ *---------------------------------------------------------
+ */
+outxy20(x, y)
+int x, y; /* The coordinates to be output. Note:
+ * these are world coordinates, not screen
+ * ones. We scale in this routine.
+ */
+{
+ char s1[4], s2[4], s3[4];
+ x = ((x - xbot) * scale)>>12;
+ y = ((y - ybot) * scale)>>12;
+ chex(((y>>8)&03) | ((x>>6)&014), s1, 1);
+ chex(x&0377, s2, 2);
+ chex(y&0377, s3, 2);
+ fprintf(stdout, "%s%s%s", s1, s2, s3);
+}
+
+/*---------------------------------------------------------
+ * This routine sets the display's current color.
+ *
+ * Results: None.
+ *
+ * Side Effects:
+ * The current color in the display is set to pcolor, if it
+ * isn't that already.
+ *---------------------------------------------------------
+ */
+setcolor(pcolor)
+char *pcolor; /* Pointer to a string giving the desired
+ * color in hexadecimal.
+ */
+{
+ static char curcolor[] = "xx";
+ if ((pcolor[0] != curcolor[0]) || (pcolor[1] != curcolor[1]))
+ {
+ curcolor[0] = pcolor[0];
+ curcolor[1] = pcolor[1];
+ putc('L', stdout);
+ fputs(curcolor, stdout);
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/Makefile b/usr/src/ucbcmd/plot/libplot/bitgraph/Makefile
new file mode 100644
index 0000000000..0da2659fe9
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/Makefile
@@ -0,0 +1,54 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libplotbg.a
+
+OBJECTS = arc.o box.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+# TXTS allows the AT&T makefile to be bootstrapped into the NSE.
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/arc.c b/usr/src/ucbcmd/plot/libplot/bitgraph/arc.c
new file mode 100644
index 0000000000..6ba92aaddd
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/arc.c
@@ -0,0 +1,103 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "bg.h"
+
+/* should include test for equality? */
+#define side(x,y) (a*(x)+b*(y)+c > 0.0 ? 1 : -1)
+
+/* The beginning and ending points must be distinct. */
+arc(xc,yc,xbeg,ybeg,xend,yend)
+int xc,yc,xbeg,ybeg,xend,yend;
+{
+ double r, radius, costheta, sintheta;
+ double a, b, c, x, y, tempX;
+ int right_side;
+
+ int screen_xc = scaleX(xc);
+ int screen_yc = scaleY(yc);
+
+ /* It is more convienient to beg and end relative to center. */
+ int screen_xbeg = scaleX(xbeg) - screen_xc;
+ int screen_ybeg = scaleY(ybeg) - screen_yc;
+
+ int screen_xend = scaleX(xend) - screen_xc;
+ int screen_yend = scaleY(yend) - screen_yc;
+
+ /* probably should check that arc is truely circular */
+ r = sqrt( (double) (screen_xbeg*screen_xbeg + screen_ybeg*screen_ybeg) );
+
+ /*
+ This method is reasonably efficient, clean, and clever.
+ The easy part is generating the next point on the arc. This is
+ done by rotating the points by the angle theta. Theta is chosen
+ so that no rotation will cause more than one pixel of a move.
+ This corresponds to a triangle having x side of r and y side of 1.
+ The rotation is done (way) below inside the loop.
+
+ Note: all calculations are done in screen coordinates.
+ */
+ if (r <= 1.0) {
+ /* radius is mapped to length < 1*/
+ point(xc,yc);
+ return;
+ }
+
+ radius = sqrt(r*r + 1.0);
+ sintheta = 1.0/radius;
+ costheta = r/radius;
+
+ /*
+ The hard part of drawing an arc is figuring out when to stop.
+ This method works by drawing the line from the beginning point
+ to the ending point. This splits the plane in half, with the
+ arc that we wish to draw on one side of the line. If we evaluate
+ side(x,y) = a*x + b*y + c, then all of the points on one side of the
+ line will result in side being positive, and all the points on the
+ other side of the line will result in side being negative.
+
+ We want to draw the arc in a counter-clockwise direction, so we
+ must find out what the sign of "side" is for a point which is to the
+ "right" of a line drawn from "beg" to "end". A point which must lie
+ on the right is [xbeg + (yend-ybeg), ybeg - (xend-xbeg)]. (This
+ point is perpendicular to the line at "beg").
+
+ Thus, we compute side of the above point, and then compare the
+ sign of side for each new point with the sign of the above point.
+ When they are different, we terminate the loop.
+ */
+
+ a = (double) (screen_yend - screen_ybeg);
+ b = (double) (screen_xend - screen_xbeg);
+ c = (double) (screen_yend*screen_xbeg - screen_xend*screen_ybeg);
+ right_side = side(screen_xbeg + (screen_yend-screen_ybeg),
+ screen_ybeg - (screen_xend-screen_xbeg) );
+
+ x = screen_xbeg;
+ y = screen_ybeg;
+ move(xbeg, ybeg);
+ do {
+ currentx = screen_xc + (int) (x + 0.5);
+ currenty = screen_yc + (int) (y + 0.5);
+ putchar( ESC );
+ printf(":%d;%dd", currentx, currenty);
+ tempX = x;
+ x = x*costheta - y*sintheta;
+ y = tempX*sintheta + y*costheta;
+ } while( side(x,y) == right_side );
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/bg.h b/usr/src/ucbcmd/plot/libplot/bitgraph/bg.h
new file mode 100644
index 0000000000..1cfbe5ce23
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/bg.h
@@ -0,0 +1,38 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Displays plot files on a bbn bitgraph terminal.
+ */
+
+#include <stdio.h>
+#include <math.h>
+
+#define ESC 033
+#define PI 3.141592659
+
+/* The graphics address range is 0..XMAX, 0..YMAX. */
+#define XMAX 768
+#define YMAX 1024
+#define scaleX(xi) ((int) ((xi - lowx)*scale +0.5))
+#define scaleY(yi) ((int) ((yi - lowy)*scale +0.5))
+
+extern int currentx;
+extern int currenty;
+extern double lowx;
+extern double lowy;
+extern double scale;
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/box.c b/usr/src/ucbcmd/plot/libplot/bitgraph/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/circle.c b/usr/src/ucbcmd/plot/libplot/bitgraph/circle.c
new file mode 100644
index 0000000000..3fe8b150e9
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/circle.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+circle (xc,yc,r)
+int xc,yc,r;
+{
+ arc(xc,yc, xc+r,yc, xc-r,yc);
+ arc(xc,yc, xc-r,yc, xc+r,yc);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/close.c b/usr/src/ucbcmd/plot/libplot/bitgraph/close.c
new file mode 100644
index 0000000000..e38aa6d949
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/close.c
@@ -0,0 +1,32 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+#include <signal.h>
+#include "bg.h"
+
+closepl()
+{
+ /* recieve interupts */
+ signal(SIGINT, SIG_IGN);
+
+ /* exit graphics mode */
+ putchar( ESC );
+ printf("[H");
+ exit(0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/cont.c b/usr/src/ucbcmd/plot/libplot/bitgraph/cont.c
new file mode 100644
index 0000000000..21e8dd0a93
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/cont.c
@@ -0,0 +1,29 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+#include "bg.h"
+
+cont(xi,yi)
+int xi,yi;
+{
+ currentx = scaleX(xi);
+ currenty = scaleY(yi);
+ putchar( ESC );
+ printf(":%d;%dd", currentx, currenty);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/dot.c b/usr/src/ucbcmd/plot/libplot/bitgraph/dot.c
new file mode 100644
index 0000000000..6aa953f3a3
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/dot.c
@@ -0,0 +1,21 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/erase.c b/usr/src/ucbcmd/plot/libplot/bitgraph/erase.c
new file mode 100644
index 0000000000..f250b14ac4
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/erase.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+#include "bg.h"
+
+erase()
+{
+ putchar( ESC );
+ printf("[H");
+ putchar( ESC );
+ printf("[J");
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/label.c b/usr/src/ucbcmd/plot/libplot/bitgraph/label.c
new file mode 100644
index 0000000000..bcf807b09f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/label.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+label(s)
+char *s;
+{
+ printf("%s", s);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/line.c b/usr/src/ucbcmd/plot/libplot/bitgraph/line.c
new file mode 100644
index 0000000000..ee9771b65e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/line.c
@@ -0,0 +1,33 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+#include "bg.h"
+
+line(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ if(scaleX(x0)==currentx && scaleY(y0)==currenty)
+ cont(x1,y1);
+ else if(scaleX(x1)==currentx && scaleY(y1)==currenty)
+ cont(x0,y0);
+ else{
+ move(x0,y0);
+ cont(x1,y1);
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/linemod.c b/usr/src/ucbcmd/plot/libplot/bitgraph/linemod.c
new file mode 100644
index 0000000000..11f3e9e517
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/linemod.c
@@ -0,0 +1,21 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+linemod(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/move.c b/usr/src/ucbcmd/plot/libplot/bitgraph/move.c
new file mode 100644
index 0000000000..7fb50e4584
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/move.c
@@ -0,0 +1,29 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+#include "bg.h"
+
+move(xi,yi)
+int xi,yi;
+{
+ currentx = scaleX(xi);
+ currenty = scaleY(yi);
+ putchar( ESC );
+ printf(":%d;%dm", currentx, currenty);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/open.c b/usr/src/ucbcmd/plot/libplot/bitgraph/open.c
new file mode 100644
index 0000000000..9735e7a3cc
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/open.c
@@ -0,0 +1,43 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+/*
+ * Displays plot files on a BBN bitgraph terminal.
+ */
+
+#include <signal.h>
+#include "bg.h"
+
+int currentx = 0;
+int currenty = 0;
+double lowx = 0.0;
+double lowy = 0.0;
+double scale = 1.0;
+
+openpl()
+{
+ void closepl();
+
+ /* catch interupts */
+ signal(SIGINT, closepl);
+ currentx = 0;
+ currenty = 0;
+
+ space(0, 0, XMAX, YMAX);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/point.c b/usr/src/ucbcmd/plot/libplot/bitgraph/point.c
new file mode 100644
index 0000000000..a177c3bffd
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/point.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+point(xi, yi)
+int xi, yi;
+{
+ move(xi, yi);
+ label(".");
+}
diff --git a/usr/src/ucbcmd/plot/libplot/bitgraph/space.c b/usr/src/ucbcmd/plot/libplot/bitgraph/space.c
new file mode 100644
index 0000000000..e98efec98b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/bitgraph/space.c
@@ -0,0 +1,31 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+
+#include "bg.h"
+
+space(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ double scalex, scaley;
+ lowx = x0;
+ lowy = y0;
+ scalex = XMAX/(double)(x1-lowx);
+ scaley = YMAX/(double)(y1-lowy);
+ scale = scalex < scaley ? scalex : scaley;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/Makefile b/usr/src/ucbcmd/plot/libplot/dumb/Makefile
new file mode 100644
index 0000000000..ca99ef4be1
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libdumb.a
+
+OBJECTS = arc.o box.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/arc.c b/usr/src/ucbcmd/plot/libplot/dumb/arc.c
new file mode 100644
index 0000000000..7bd038a3e2
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/arc.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+arc(xc,yc,xbeg,ybeg,xend,yend)
+int xc,yc,xbeg,ybeg,xend,yend;
+{
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/box.c b/usr/src/ucbcmd/plot/libplot/dumb/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/circle.c b/usr/src/ucbcmd/plot/libplot/dumb/circle.c
new file mode 100644
index 0000000000..6dab0dce38
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/circle.c
@@ -0,0 +1,19 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+circle(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/close.c b/usr/src/ucbcmd/plot/libplot/dumb/close.c
new file mode 100644
index 0000000000..979b8dc369
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/close.c
@@ -0,0 +1,34 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <signal.h>
+#include "dumb.h"
+
+closepl()
+{
+ int i, j;
+
+ for(j=0; j<LINES; j++){
+ for(i=0; i<COLS; i++){
+ printf("%c", screenmat[i][j]);
+ }
+ printf("\n");
+ }
+ signal(SIGINT, SIG_IGN);
+ exit(0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/cont.c b/usr/src/ucbcmd/plot/libplot/dumb/cont.c
new file mode 100644
index 0000000000..3233e5b49f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/cont.c
@@ -0,0 +1,29 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+cont(x, y)
+ int x,y;
+{
+ int x1, y1;
+ x1 = x;
+ y1 = y;
+ scale(x1, y1);
+ dda_line('*', currentx, currenty, x, y);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/dot.c b/usr/src/ucbcmd/plot/libplot/dumb/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/dumb.h b/usr/src/ucbcmd/plot/libplot/dumb/dumb.h
new file mode 100644
index 0000000000..acf77ba64d
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/dumb.h
@@ -0,0 +1,39 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * This accepts plot file formats and produces the appropriate plots
+ * for dumb terminals. It can also be used for printing terminals and
+ * lineprinter listings, although there is no way to specify number of
+ * lines and columns different from your terminal. This would be easy
+ * to change, and is left as an exercise for the reader.
+ */
+
+#include <math.h>
+
+#define scale(x,y) y = LINES-1-(LINES*y/rangeY +minY); x = COLS*x/rangeX + minX
+
+extern int minX, rangeX; /* min and range of x */
+extern int minY, rangeY; /* min and range of y */
+extern int currentx, currenty;
+extern int COLS, LINES;
+
+/* A very large screen! (probably should use malloc) */
+#define MAXCOLS 132
+#define MAXLINES 90
+
+extern char screenmat[MAXCOLS][MAXLINES];
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/erase.c b/usr/src/ucbcmd/plot/libplot/dumb/erase.c
new file mode 100644
index 0000000000..dae078fe39
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/erase.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+erase()
+{
+ register int i, j;
+
+ for(i=0;i<COLS;i++)
+ for(j=0;j<LINES;j++)
+ screenmat[i][j] = ' ';
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/label.c b/usr/src/ucbcmd/plot/libplot/dumb/label.c
new file mode 100644
index 0000000000..db28a34284
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/label.c
@@ -0,0 +1,31 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+label(string)
+ char *string;
+{
+ while(*string != '\0' && currentx < COLS){
+ screenmat[currentx][currenty] = *string++;
+ currentx++;
+ }
+ if(currentx == COLS)
+ currentx = currentx-1;
+
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/line.c b/usr/src/ucbcmd/plot/libplot/dumb/line.c
new file mode 100644
index 0000000000..01ae1418eb
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/line.c
@@ -0,0 +1,34 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+line(x0, y0, x1, y1)
+ int x0, y0, x1, y1;
+{
+ int x,y;
+
+ scale(x0, y0);
+ x = x1;
+ y = y1;
+ scale(x, y);
+ currentx = x0;
+ currenty = y0;
+ screenmat[currentx][currenty] = '*';
+ dda_line('*', x0, y0, x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/linemod.c b/usr/src/ucbcmd/plot/libplot/dumb/linemod.c
new file mode 100644
index 0000000000..47ceef55d3
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/linemod.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+linemod(s)
+char *s;
+{
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/move.c b/usr/src/ucbcmd/plot/libplot/dumb/move.c
new file mode 100644
index 0000000000..2e6ea7ad32
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/move.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+move(x,y)
+int x,y;
+{
+ scale(x, y);
+ currentx = x;
+ currenty = y;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/open.c b/usr/src/ucbcmd/plot/libplot/dumb/open.c
new file mode 100644
index 0000000000..26dad93202
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/open.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+ * This accepts plot file formats and produces the appropriate plots
+ * for dumb terminals. It can also be used for printing terminals and
+ * lineprinter listings, although there is no way to specify number of
+ * lines and columns different from your terminal. This would be easy
+ * to change, and is left as an exercise for the reader.
+ */
+
+#include <signal.h>
+#include "dumb.h"
+
+int minX, rangeX; /* min and range of x */
+int minY, rangeY; /* min and range of y */
+int currentx,currenty;
+int COLS,LINES;
+
+/* A very large screen! (probably should use malloc) */
+char screenmat[MAXCOLS][MAXLINES];
+
+openpl()
+{
+ void closepl();
+ int i, j;
+ char *term, *getenv();
+ char bp[1024];
+
+ term = getenv("TERM");
+ tgetent(bp, term);
+
+ COLS = tgetnum("co");
+ if (COLS > MAXCOLS)
+ COLS = MAXCOLS;
+ if (COLS < 0)
+ COLS = 48; /* lower bound on # of cols? */
+ COLS--; /* prevent auto wrap */
+
+ LINES = tgetnum("li");
+ if (LINES > MAXLINES)
+ LINES = MAXLINES;
+ if (LINES < 0)
+ LINES = 20; /* lower bound on # of lines? */
+
+ for(i=0; i<COLS; i++)
+ for(j=0; j<LINES; j++)
+ screenmat[i][j] = ' ';
+
+ signal(SIGINT, closepl);
+ currentx = currenty = 0;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/point.c b/usr/src/ucbcmd/plot/libplot/dumb/point.c
new file mode 100644
index 0000000000..c6e72da637
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/point.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+point(x, y)
+ int x,y;
+{
+ scale(x, y);
+ currentx = x;
+ currenty = y;
+ screenmat[currentx][currenty] = '*';
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/space.c b/usr/src/ucbcmd/plot/libplot/dumb/space.c
new file mode 100644
index 0000000000..dad2cff44b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/space.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+space(x0, y0, x1, y1)
+ int x0, y0, x1, y1;
+{
+ minX = x0;
+ rangeX = x1 -x0;
+ minY = y0;
+ rangeY = y1 - y0;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/dumb/subr.c b/usr/src/ucbcmd/plot/libplot/dumb/subr.c
new file mode 100644
index 0000000000..102c483878
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/dumb/subr.c
@@ -0,0 +1,57 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "dumb.h"
+
+/* Does not plot first point -- assumed that it is already plotted */
+dda_line(ch, x0, y0, x1, y1)
+ char ch;
+ int x0, y0; /* already transformed to screen coords */
+ int x1, y1; /* untransformed */
+{
+ int length, i;
+ double deltaX, deltaY;
+ double x, y;
+ double floor();
+ int abs();
+
+ scale(x1, y1);
+
+ length = abs(x1 - x0);
+ if (abs(y1 -y0) > length)
+ length = abs(y1 - y0);
+
+ if (length == 0)
+ return;
+
+ deltaX = (double) (x1 - x0)/(double) length;
+ deltaY = (double) (y1 - y0)/(double) length;
+
+ x = (double) x0 + 0.5;
+ y = (double) y0 + 0.5;
+
+ for (i=0; i < length; ++i) {
+ x += deltaX;
+ y += deltaY;
+ x0 = floor(x);
+ y0 = floor(y);
+ currentx = x0;
+ currenty = y0;
+ screenmat[currentx][currenty] = ch;
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/Makefile b/usr/src/ucbcmd/plot/libplot/gigi/Makefile
new file mode 100644
index 0000000000..e423dee541
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libgigi.a
+
+OBJECTS = arc.o box.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/arc.c b/usr/src/ucbcmd/plot/libplot/gigi/arc.c
new file mode 100644
index 0000000000..edaec6a548
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/arc.c
@@ -0,0 +1,57 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+/*
+ * gigi requires knowing the anlge of arc. To do this, the triangle formula
+ * c^2 = a^2 + b^2 - 2*a*b*cos(angle)
+ * is used where "a" and "b" are the radius of the circle and "c" is the
+ * distance between the beginning point and the end point.
+ *
+ * This gives us "angle" or angle - 180. To find out which, draw a line from
+ * beg to center. This splits the plane in half. All points on one side of the
+ * plane will have the same sign when plugged into the equation for the line.
+ * Pick a point on the "right side" of the line (see program below). If "end"
+ * has the same sign as this point does, then they are both on the same side
+ * of the line and so angle is < 180. Otherwise, angle > 180.
+ */
+
+#define side(x,y) (a*(x)+b*(y)+c > 0.0 ? 1 : -1)
+
+arc(xcent,ycent,xbeg,ybeg,xend,yend)
+int xcent,ycent,xbeg,ybeg,xend,yend;
+{
+ double radius2, c2;
+ double a,b,c;
+ int angle;
+
+ /* Probably should check that this is really a circular arc. */
+ radius2 = (xcent-xbeg)*(xcent-xbeg) + (ycent-ybeg)*(ycent-ybeg);
+ c2 = (xend-xbeg)*(xend-xbeg) + (yend-ybeg)*(yend-ybeg);
+ angle = (int) ( 180.0/PI * acos(1.0 - c2/(2.0*radius2)) + 0.5 );
+
+ a = (double) (ycent - ybeg);
+ b = (double) (xcent - xbeg);
+ c = (double) (ycent*xbeg - xcent*ybeg);
+ if (side(xbeg + (ycent-ybeg), ybeg - (xcent-xbeg)) != side(xend,yend))
+ angle += 180;
+
+ move(xcent, ycent);
+ printf("C(A%d c)[%d,%d]", angle, xbeg, ybeg);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/box.c b/usr/src/ucbcmd/plot/libplot/gigi/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/circle.c b/usr/src/ucbcmd/plot/libplot/gigi/circle.c
new file mode 100644
index 0000000000..f3442861ab
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/circle.c
@@ -0,0 +1,30 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+circle (xc,yc,r)
+int xc,yc,r;
+{
+ if(r < 1){
+ point(xc, yc);
+ return;
+ }
+ move(xc, yc);
+ printf("C[%d]", r);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/close.c b/usr/src/ucbcmd/plot/libplot/gigi/close.c
new file mode 100644
index 0000000000..9373a4729d
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/close.c
@@ -0,0 +1,32 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <signal.h>
+#include "gigi.h"
+
+closepl()
+{
+ /* recieve interupts */
+ signal(SIGINT, SIG_IGN);
+
+ /* exit graphics mode */
+ putchar( ESC );
+ putchar('\\');
+
+ exit(0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/cont.c b/usr/src/ucbcmd/plot/libplot/gigi/cont.c
new file mode 100644
index 0000000000..8005fd1f97
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/cont.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+cont(xi,yi)
+int xi,yi;
+{
+ currentx = xsc(xi);
+ currenty = ysc(yi);
+ printf("V[%d,%d]",currentx, currenty);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/dot.c b/usr/src/ucbcmd/plot/libplot/gigi/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/erase.c b/usr/src/ucbcmd/plot/libplot/gigi/erase.c
new file mode 100644
index 0000000000..d50da21696
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/erase.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+erase()
+{
+ printf("S(E)");
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/gigi.h b/usr/src/ucbcmd/plot/libplot/gigi/gigi.h
new file mode 100644
index 0000000000..d23c6065b7
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/gigi.h
@@ -0,0 +1,42 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Displays plot files on a gigi "graphics" terminal.
+ */
+
+#include <stdio.h>
+#include <math.h>
+
+#define ESC 033
+#define PI 3.141592659
+
+/*
+ * The graphics address range is 0..XMAX, YMAX..0 where (0, YMAX) is the
+ * lower left corner.
+ */
+#define XMAX 767
+#define YMAX 479
+#define xsc(xi) ((int) ((xi -lowx)*scalex +0.5))
+#define ysc(yi) ((int) (YMAX - (yi - lowy)*scaley +0.5))
+
+extern int currentx;
+extern int currenty;
+extern double lowx;
+extern double lowy;
+extern double scalex;
+extern double scaley;
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/label.c b/usr/src/ucbcmd/plot/libplot/gigi/label.c
new file mode 100644
index 0000000000..e5f0a28a8d
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/label.c
@@ -0,0 +1,30 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+label(s)
+char *s;
+{
+ printf("T(S0 H2 D0 I0) \"");
+ for(;*s!='\0';s++) {
+ putchar(*s);
+ if (*s == '"') putchar('"');
+ }
+ putchar('"');
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/line.c b/usr/src/ucbcmd/plot/libplot/gigi/line.c
new file mode 100644
index 0000000000..61aca3c623
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/line.c
@@ -0,0 +1,32 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+line(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ if(xsc(x0)==currentx && ysc(y0)==currenty)
+ cont(x1,y1);
+ else if(xsc(x1)==currentx && ysc(y1)==currenty)
+ cont(x0,y0);
+ else{
+ move(x0,y0);
+ cont(x1,y1);
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/linemod.c b/usr/src/ucbcmd/plot/libplot/gigi/linemod.c
new file mode 100644
index 0000000000..dc7b011937
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/linemod.c
@@ -0,0 +1,79 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+linemod( line )
+char *line;
+{
+ /*
+ * Note that the bit patterns could be compacted using the
+ * repeat field conventions. They aren't for clarity.
+ * Examples of almost identical packed patterns are in the
+ * comments.
+ * If linemod is changed really often, a ~15% savings
+ * could be achieved.
+ */
+ if ( *(line) == 's' ) {
+ if ( *(++line) == 'o' ) {
+ /*
+ * solid mode 1
+ */
+ printf( "W(P1)" );
+ return;
+ }
+ else if ( *(line) == 'h' ) {
+ /*
+ * shortdashed mode 4
+ * printf( "W(P000111)" );
+ */
+ printf( "W(P00011100)" );
+ return;
+ }
+ }
+ else if ( *(line) == 'd' ) {
+ if ( *(++line) == 'o' && *(++line) == 't' ) {
+ if ( *(++line) == 't' ) {
+ /*
+ * dotted mode 2
+ * printf( "W(P00001)" );
+ */
+ printf( "W(P10000000)" );
+ return;
+ }
+ else if ( *(line) == 'd' ) {
+ /*
+ * dotdashed mode 3
+ * printf( "W(P0110010)" );
+ */
+ printf( "W(P10001100)" );
+ return;
+ }
+ }
+ }
+ else if ( *(line) == 'l' ) {
+ /*
+ * longdashed mode 5
+ * printf( "W(P11100)" );
+ */
+ printf( "W(P11111100)" );
+ return;
+ }
+ printf( "W(P1)" ); /* default to solid */
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/move.c b/usr/src/ucbcmd/plot/libplot/gigi/move.c
new file mode 100644
index 0000000000..d575ff6aa0
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/move.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+move(xi,yi)
+int xi,yi;
+{
+ currentx = xsc(xi);
+ currenty = ysc(yi);
+ printf("P[%d,%d]",currentx, currenty);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/open.c b/usr/src/ucbcmd/plot/libplot/gigi/open.c
new file mode 100644
index 0000000000..7f23b8479e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/open.c
@@ -0,0 +1,48 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+ * Displays plot files on a gigi "graphics" terminal.
+ */
+
+#include <signal.h>
+#include "gigi.h"
+
+int currentx = 0;
+int currenty = 0;
+double lowx = 0.0;
+double lowy = 0.0;
+double scalex = 1.0;
+double scaley = 1.0;
+
+openpl()
+{
+ void closepl();
+
+ /* catch interupts */
+ signal(SIGINT, closepl);
+ currentx = 0;
+ currenty = 0;
+ /* enter grapics mode */
+ putchar(ESC); putchar('P'); putchar('p');
+
+ /* set some parameters */
+ printf("S(I0 T0 [0,0])");
+
+ space(0, 0, XMAX, YMAX);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/point.c b/usr/src/ucbcmd/plot/libplot/gigi/point.c
new file mode 100644
index 0000000000..f9579ce205
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/point.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+point(xi,yi)
+int xi,yi;
+{
+ if(xsc(xi)!=currentx || ysc(yi)!=currenty)
+ move(xi,yi);
+ printf("V[]");
+}
diff --git a/usr/src/ucbcmd/plot/libplot/gigi/space.c b/usr/src/ucbcmd/plot/libplot/gigi/space.c
new file mode 100644
index 0000000000..ea3ed79b6b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/gigi/space.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "gigi.h"
+
+space(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ lowx = x0;
+ lowy = y0;
+ scalex = XMAX/(x1-lowx);
+ scaley = YMAX/(y1-lowy);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/Makefile b/usr/src/ucbcmd/plot/libplot/hp2648/Makefile
new file mode 100644
index 0000000000..44f64ec2a8
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/Makefile
@@ -0,0 +1,54 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libhp2648.a
+
+OBJECTS = arc.o box.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+#include ../../../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/arc.c b/usr/src/ucbcmd/plot/libplot/hp2648/arc.c
new file mode 100644
index 0000000000..6380a8ae49
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/arc.c
@@ -0,0 +1,63 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+arc(xcent,ycent,xbeg,ybeg,xend,yend)
+int xcent,ycent,xbeg,ybeg,xend,yend;
+{
+ double costheta,sintheta,x,y,xn,r;
+ double x1,y1,x2,y2;
+ int xi,yi,crosspflag,crossp;
+
+ r = (xcent-xbeg)*(xcent-xbeg)+(ycent-ybeg)*(ycent-ybeg);
+ r = pow(r,0.5);
+ if(r<1){
+ point(xcent,ycent);
+ return;
+ }
+ sintheta = 1.0/r;
+ costheta = pow(1-sintheta*sintheta,0.5);
+ xi = x = xbeg-xcent;
+ yi = y = ybeg-ycent;
+ x1 = xcent;
+ y1 = ycent;
+ x2 = xend;
+ y2 = yend;
+ crosspflag = 0;
+ do {
+ crossp = cross_product(x1,y1,x2,y2,x,y);
+ if(crossp >0 && crosspflag == 0) crosspflag = 1;
+ point(xcent+xi,ycent+yi);
+ xn = x;
+ xi = x = x*costheta + y*sintheta;
+ yi = y = y*costheta - xn*sintheta;
+ } while( crosspflag == 0 || crossp >0);
+}
+
+cross_product(x1,y1,x2,y2,x3,y3)
+double x1,x2,x3,y1,y2,y3;
+{
+ double z,a,b;
+ a = (y3-y2)*(x2-x1);
+ b = (x3-x2)*(y2-y1);
+ z = a-b;
+ if(z<0) return(-1);
+ if(z>0) return(1);
+ return(0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/box.c b/usr/src/ucbcmd/plot/libplot/hp2648/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/circle.c b/usr/src/ucbcmd/plot/libplot/hp2648/circle.c
new file mode 100644
index 0000000000..692e3302fc
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/circle.c
@@ -0,0 +1,41 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+circle (xc,yc,r)
+int xc,yc,r;
+{
+ double costheta,sintheta,x,y,xn;
+ int xi,yi;
+
+ if(r<1){
+ point(xc,yc);
+ return;
+ }
+ sintheta = 1.0/r;
+ costheta = pow(1-sintheta*sintheta,0.5);
+ xi = x = r;
+ yi = y = 0;
+ do {
+ point(xc+xi,yc+yi);
+ xn = x;
+ xi = x = x*costheta + y*sintheta;
+ yi = y = y*costheta - xn*sintheta;
+ } while( ! (yi==0 && xi >= r-1));
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/close.c b/usr/src/ucbcmd/plot/libplot/hp2648/close.c
new file mode 100644
index 0000000000..f364793348
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/close.c
@@ -0,0 +1,29 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+closepl()
+{
+ putchar('Z');
+ fflush(stdout);
+ if ( shakehands == TRUE ) {
+ stty(fildes, &sarg);
+ close(fildes);
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/cont.c b/usr/src/ucbcmd/plot/libplot/hp2648/cont.c
new file mode 100644
index 0000000000..84ca2d0000
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/cont.c
@@ -0,0 +1,34 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+cont(xi,yi)
+int xi,yi;
+{
+ char xb1,xb2,yb1,yb2;
+ itoa(xsc(xi),&xb1,&xb2);
+ itoa(ysc(yi),&yb1,&yb2);
+ buffready(4);
+ putchar(xb2);
+ putchar(xb1);
+ putchar(yb2);
+ putchar(yb1);
+ currentx = xsc(xi);
+ currenty = ysc(yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/dot.c b/usr/src/ucbcmd/plot/libplot/hp2648/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/erase.c b/usr/src/ucbcmd/plot/libplot/hp2648/erase.c
new file mode 100644
index 0000000000..15aeb53aad
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/erase.c
@@ -0,0 +1,32 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+erase()
+{
+ buffready(8);
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(DISPLAY);
+ putchar('a');
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(PLOT);
+ putchar(BINARY);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/hp2648.h b/usr/src/ucbcmd/plot/libplot/hp2648/hp2648.h
new file mode 100644
index 0000000000..70278d20c5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/hp2648.h
@@ -0,0 +1,55 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Displays plot files on an hp2648a graphics terminals. I have heard
+ * that all hp plotting devices use the same control sequences, so this
+ * might work for all hp devices capable of plotting.
+ */
+
+#include <stdio.h>
+
+#define TERMINAL "/dev/tty"
+
+#define ENQ 05
+#define ACK 06
+#define ESC 033
+#define GRAPHIC '*'
+#define MODE 'm'
+#define PLOT 'p'
+#define DISPLAY 'd'
+#define PENUP 'a'
+#define BINARY 'i'
+#define ASCII 'f'
+#define CR '\n'
+
+#define TRUE 1
+#define FALSE 0
+
+#define xsc(xi) ((int) (xi - lowx) * scalex + 0.5)
+#define ysc(yi) ((int) (yi - lowy) * scaley + 0.5)
+
+extern int shakehands;
+extern int currentx;
+extern int currenty;
+extern int buffcount;
+extern int fildes;
+extern float lowx;
+extern float lowy;
+extern float scalex;
+extern float scaley;
+extern struct sgttyb sarg;
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/label.c b/usr/src/ucbcmd/plot/libplot/hp2648/label.c
new file mode 100644
index 0000000000..fec2cbd916
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/label.c
@@ -0,0 +1,40 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+label(s)
+char *s;
+{
+ handshake();
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar('l');
+ for(;*s!='\0';s++)
+ putchar(*s);
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar('d');
+ putchar('T');
+ handshake();
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(PLOT);
+ putchar(BINARY);
+ buffcount = 4;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/line.c b/usr/src/ucbcmd/plot/libplot/hp2648/line.c
new file mode 100644
index 0000000000..c9ae574e8f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/line.c
@@ -0,0 +1,32 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+line(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ if(xsc(x0)==currentx && ysc(y0)==currenty)
+ cont(x1,y1);
+ else if(xsc(x1)==currentx && ysc(y1)==currenty)
+ cont(x0,y0);
+ else{
+ move(x0,y0);
+ cont(x1,y1);
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/linemod.c b/usr/src/ucbcmd/plot/libplot/hp2648/linemod.c
new file mode 100644
index 0000000000..8ab4fcd1d9
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/linemod.c
@@ -0,0 +1,86 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+linemod( line )
+char *line;
+{
+ putchar('Z');
+ handshake();
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(MODE);
+ if ( *(line) == 's' ) {
+ if ( *(++line) == 'o' ) {
+ /*
+ * solid mode 1
+ */
+ putchar( '1' );
+ putchar( 'b' );
+ goto done;
+ }
+ else if ( *(line) == 'h' ) {
+ /*
+ * shortdashed mode 4
+ */
+ putchar( '6' );
+ putchar( 'b' );
+ goto done;
+ }
+ }
+ else if ( *(line) == 'd' ) {
+ if ( *(++line) == 'o' && *(++line) == 't' ) {
+ if ( *(++line) == 't' ) {
+ /*
+ * dotted mode 2
+ */
+ putchar( '7' );
+ putchar( 'b' );
+ goto done;
+ }
+ else if ( *(line) == 'd' ) {
+ /*
+ * dotdashed mode 3
+ */
+ putchar( '8' );
+ putchar( 'b' );
+ goto done;
+ }
+ }
+ }
+ else if ( *(line) == 'l' ) {
+ /*
+ * longdashed mode 5
+ */
+ putchar( '5' );
+ putchar( 'b' );
+ goto done;
+ }
+ putchar( '1' ); /* default to solid */
+ putchar( 'b' ); /* default to solid */
+done:
+ putchar( 'Z' );
+ handshake();
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(PLOT);
+ putchar(BINARY);
+ buffcount = 4;
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/move.c b/usr/src/ucbcmd/plot/libplot/hp2648/move.c
new file mode 100644
index 0000000000..25864e3f00
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/move.c
@@ -0,0 +1,35 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+move(xi,yi)
+int xi,yi;
+{
+ char xb1,xb2,yb1,yb2;
+ itoa(xsc(xi),&xb1,&xb2);
+ itoa(ysc(yi),&yb1,&yb2);
+ buffready(5);
+ putchar(PENUP);
+ putchar(xb2);
+ putchar(xb1);
+ putchar(yb2);
+ putchar(yb1);
+ currentx = xsc(xi);
+ currenty = ysc(yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/open.c b/usr/src/ucbcmd/plot/libplot/hp2648/open.c
new file mode 100644
index 0000000000..51aa8a8c92
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/open.c
@@ -0,0 +1,59 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <sgtty.h>
+#include "hp2648.h"
+
+int shakehands;
+int currentx;
+int currenty;
+int buffcount;
+int fildes;
+float lowx;
+float lowy;
+float scalex;
+float scaley;
+struct sgttyb sarg;
+
+openpl()
+{
+ if ( isatty(fileno( stdout )) ) {
+ shakehands = TRUE;
+ fildes = open(TERMINAL, 0);
+ gtty(fildes, &sarg);
+ sarg.sg_flags = sarg.sg_flags | RAW;
+ stty(fildes, &sarg);
+ sarg.sg_flags = sarg.sg_flags & ~RAW;
+ }
+ else {
+ shakehands = FALSE;
+ }
+ buffcount = 0;
+ currentx = 0;
+ currenty = 0;
+ buffready(8);
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(DISPLAY);
+ putchar('c');
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(PLOT);
+ putchar(BINARY);
+ space(0,0,720,360);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/point.c b/usr/src/ucbcmd/plot/libplot/hp2648/point.c
new file mode 100644
index 0000000000..7cca9c5de5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/point.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+point(xi,yi)
+int xi,yi;
+{
+ if(xsc(xi)!=currentx || ysc(yi)!=currenty)
+ move(xi,yi);
+ buffready(1);
+ putchar('d');
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/space.c b/usr/src/ucbcmd/plot/libplot/hp2648/space.c
new file mode 100644
index 0000000000..9524781d6a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/space.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp2648.h"
+
+space(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ lowx = x0;
+ lowy = y0;
+ scalex = 720.0/(x1-lowx);
+ scaley = 360.0/(y1-lowy);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp2648/subr.c b/usr/src/ucbcmd/plot/libplot/hp2648/subr.c
new file mode 100644
index 0000000000..3fecfb3922
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp2648/subr.c
@@ -0,0 +1,65 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <sgtty.h>
+#include "hp2648.h"
+
+handshake()
+{
+ int i;
+ char ch;
+
+ if( shakehands != TRUE )
+ return;
+ ch = ' ';
+ putchar(ENQ);
+ fflush(stdout);
+ while(1){
+ i = read(fildes, &ch, 1);
+ if(i < 0)
+ continue;
+ if(ch == ACK)
+ break;
+ putchar('Z');
+ fflush(stdout);
+ stty(fildes, &sarg);
+ exit(0);
+ }
+}
+
+buffready(n)
+int n;
+{
+ buffcount = buffcount + n;
+ if(buffcount >= 80){
+ handshake();
+ putchar(ESC);
+ putchar(GRAPHIC);
+ putchar(PLOT);
+ putchar(BINARY);
+ buffcount = n+4;
+ }
+}
+
+itoa(num,byte1,byte2)
+int num;
+char *byte1,*byte2;
+{
+ *byte1 = (num & 037) | 040;
+ *byte2 = ((num>>5) & 037) | 040;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/Makefile b/usr/src/ucbcmd/plot/libplot/hp7221/Makefile
new file mode 100644
index 0000000000..87a031bc8b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libhp7221.a
+
+OBJECTS = arc.o box.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/arc.c b/usr/src/ucbcmd/plot/libplot/hp7221/arc.c
new file mode 100644
index 0000000000..1ad9cb2c46
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/arc.c
@@ -0,0 +1,59 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+/*
+ * 7221 requires knowing the anlge of arc. To do this, the triangle formula
+ * c^2 = a^2 + b^2 - 2*a*b*cos(angle)
+ * is used where "a" and "b" are the radius of the circle and "c" is the
+ * distance between the beginning point and the end point.
+ *
+ * This gives us "angle" or angle - 180. To find out which, draw a line from
+ * beg to center. This splits the plane in half. All points on one side of the
+ * plane will have the same sign when plugged into the equation for the line.
+ * Pick a point on the "right side" of the line (see program below). If "end"
+ * has the same sign as this point does, then they are both on the same side
+ * of the line and so angle is < 180. Otherwise, angle > 180.
+ */
+
+#define side(x,y) (a*(x)+b*(y)+c > 0.0 ? 1 : -1)
+
+arc(xcent,ycent,xbeg,ybeg,xend,yend)
+int xcent,ycent,xbeg,ybeg,xend,yend;
+{
+ double radius2, c2;
+ double a,b,c;
+ int angle;
+
+ /* Probably should check that this is really a circular arc. */
+ radius2 = (xcent-xbeg)*(xcent-xbeg) + (ycent-ybeg)*(ycent-ybeg);
+ c2 = (xend-xbeg)*(xend-xbeg) + (yend-ybeg)*(yend-ybeg);
+ angle = (int) ( 180.0/PI * acos(1.0 - c2/(2.0*radius2)) + 0.5 );
+
+ a = (double) (ycent - ybeg);
+ b = (double) (xcent - xbeg);
+ c = (double) (ycent*xbeg - xcent*ybeg);
+ if (side(xbeg + (ycent-ybeg), ybeg - (xcent-xbeg)) != side(xend,yend))
+ angle += 180;
+
+ move(xcent, ycent);
+ /* Not quite implemented...
+ printf("C(A%d c)[%d,%d]", angle, xbeg, ybeg);
+ */
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/box.c b/usr/src/ucbcmd/plot/libplot/hp7221/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/circle.c b/usr/src/ucbcmd/plot/libplot/hp7221/circle.c
new file mode 100644
index 0000000000..18630d286e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/circle.c
@@ -0,0 +1,31 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+circle (xc,yc,r)
+ int xc,yc,r;
+{
+ if( r < 1 ) {
+ point( xc, yc );
+ return;
+ }
+ move( xc, yc );
+ putchar( 't' );
+ putMBN( scaleX(r) );
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/close.c b/usr/src/ucbcmd/plot/libplot/hp7221/close.c
new file mode 100644
index 0000000000..4e7aa04437
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/close.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <signal.h>
+#include "hp7221.h"
+
+closepl()
+{
+ /* receive interupts */
+ signal(SIGINT, SIG_IGN);
+ printf( "v@}" ); /* Put pen away. */
+ fflush( stdout );
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/cont.c b/usr/src/ucbcmd/plot/libplot/hp7221/cont.c
new file mode 100644
index 0000000000..240655ae9f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/cont.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+cont(xi,yi)
+int xi,yi;
+{
+ currentx = scaleX(xi);
+ currenty = scaleY(yi);
+ putchar( 'q' );
+ putMBP( currentx, currenty );
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/dot.c b/usr/src/ucbcmd/plot/libplot/hp7221/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/erase.c b/usr/src/ucbcmd/plot/libplot/hp7221/erase.c
new file mode 100644
index 0000000000..f255de3efd
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/erase.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+erase(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/hp7221.h b/usr/src/ucbcmd/plot/libplot/hp7221/hp7221.h
new file mode 100644
index 0000000000..ca4274dd5f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/hp7221.h
@@ -0,0 +1,44 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Displays plot files on an HP7221 plotter.
+ * Cloned from bgplot.c and gigiplot.c by Jim Kleckner
+ * Thu Jun 30 13:35:04 PDT 1983
+ * Requires a handshaking program such as hp7221cat to get
+ * the plotter open and ready.
+ */
+
+#include <stdio.h>
+#include <math.h>
+
+#define ESC 033
+#define PI 3.141592659
+#define ENDOFSTRING 03
+
+/* The graphics address range is 0..XMAX, 0..YMAX. */
+#define XMAX 1800
+#define YMAX 1800
+
+#define scaleX(xi) ((int) ((xi - lowx)*scale +0.5))
+#define scaleY(yi) ((int) ((yi - lowy)*scale +0.5))
+
+extern int currentx;
+extern int currenty;
+extern double lowx;
+extern double lowy;
+extern double scale;
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/label.c b/usr/src/ucbcmd/plot/libplot/hp7221/label.c
new file mode 100644
index 0000000000..19434255a7
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/label.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+label(s)
+char *s;
+{
+ printf("~'%s", s);
+ putchar( ENDOFSTRING );
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/line.c b/usr/src/ucbcmd/plot/libplot/hp7221/line.c
new file mode 100644
index 0000000000..75f35abc4c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/line.c
@@ -0,0 +1,32 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+line(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ if(scaleX(x0)==currentx && scaleY(y0)==currenty)
+ cont(x1,y1);
+ else if(scaleX(x1)==currentx && scaleY(y1)==currenty)
+ cont(x0,y0);
+ else{
+ move(x0,y0);
+ cont(x1,y1);
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/linemod.c b/usr/src/ucbcmd/plot/libplot/hp7221/linemod.c
new file mode 100644
index 0000000000..f950e8d4ef
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/linemod.c
@@ -0,0 +1,78 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+linemod( line )
+char *line;
+{
+ /*
+ * Note that the bit patterns could be compacted using the
+ * repeat field conventions. They aren't for clarity.
+ * Examples of almost identical packed patterns are in the
+ * comments.
+ * If linemod is changed really often, a ~15% savings
+ * could be achieved.
+ */
+ if ( *(line) == 's' ) {
+ if ( *(++line) == 'o' ) {
+ /*
+ * solid mode 1
+ */
+ printf( "vA" );
+ return;
+ }
+ else if ( *(line) == 'h' ) {
+ /*
+ * shortdashed mode 4
+ */
+ printf( "vD" );
+ return;
+ }
+ }
+ else if ( *(line) == 'd' ) {
+ if ( *(++line) == 'o' && *(++line) == 't' ) {
+ if ( *(++line) == 't' ) {
+ /*
+ * dotted mode 2
+ * printf( "W(P00001)" );
+ */
+ printf( "vB" );
+ return;
+ }
+ else if ( *(line) == 'd' ) {
+ /*
+ * dotdashed mode 3
+ * printf( "W(P0110010)" );
+ */
+ printf( "vC" );
+ return;
+ }
+ }
+ }
+ else if ( *(line) == 'l' ) {
+ /*
+ * longdashed mode 5
+ * printf( "W(P11100)" );
+ */
+ printf( "vE" );
+ return;
+ }
+ printf( "vA" );
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/move.c b/usr/src/ucbcmd/plot/libplot/hp7221/move.c
new file mode 100644
index 0000000000..9cd6d103e3
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/move.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+move(xi,yi)
+int xi,yi;
+{
+ currentx = scaleX(xi);
+ currenty = scaleY(yi);
+ putchar( 'p' );
+ putMBP( currentx, currenty );
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/open.c b/usr/src/ucbcmd/plot/libplot/hp7221/open.c
new file mode 100644
index 0000000000..a64280367f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/open.c
@@ -0,0 +1,52 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+ * Displays plot files on an HP7221 plotter.
+ * Cloned from bgplot.c and gigiplot.c by Jim Kleckner
+ * Thu Jun 30 13:35:04 PDT 1983
+ * Requires a handshaking program such as hp7221cat to get
+ * the plotter open and ready.
+ */
+
+#include <signal.h>
+#include "hp7221.h"
+
+int currentx = 0;
+int currenty = 0;
+double lowx = 0.0;
+double lowy = 0.0;
+double scale = 1.0;
+
+openpl()
+{
+ void closepl();
+
+ /* catch interupts */
+ signal(SIGINT, closepl);
+ currentx = 0;
+ currenty = 0;
+ printf( "~VR~W" );
+ putMBP( 800, 2000 );
+ putMBP( 7600, 9600 );
+ printf( "~S" );
+ putMBP( XMAX, YMAX );
+ printf( "vA~*z" );
+
+ space(0,0,XMAX,YMAX);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/point.c b/usr/src/ucbcmd/plot/libplot/hp7221/point.c
new file mode 100644
index 0000000000..c5a4d12a15
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/point.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+point(xi,yi)
+int xi,yi;
+{
+ if(scaleX(xi)!=currentx || scaleY(yi)!=currenty)
+ move(xi,yi);
+ cont(xi, yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/space.c b/usr/src/ucbcmd/plot/libplot/hp7221/space.c
new file mode 100644
index 0000000000..9792bbcc1b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/space.c
@@ -0,0 +1,30 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+space(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ double scalex, scaley;
+ lowx = x0;
+ lowy = y0;
+ scalex = XMAX/(double)(x1-lowx);
+ scaley = YMAX/(double)(y1-lowy);
+ scale = scalex < scaley ? scalex : scaley;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/hp7221/subr.c b/usr/src/ucbcmd/plot/libplot/hp7221/subr.c
new file mode 100644
index 0000000000..74f3d407fb
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/hp7221/subr.c
@@ -0,0 +1,83 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "hp7221.h"
+
+putMBP( x, y )
+ int x, y;
+{
+ int chr;
+
+ chr = ( x >> 10 ) & 017;
+ chr|= 0140;
+ putchar( chr );
+ chr = ( x >> 4 ) & 077;
+ if ( chr < 32 ) {
+ chr += 64;
+ }
+ putchar( chr );
+ chr = ( y >> 12 ) & 03;
+ chr|= ( x << 2 ) & 071;
+ if ( chr < 32 ) {
+ chr += 64;
+ }
+ putchar( chr );
+ chr = ( y >> 6 ) & 077;
+ if ( chr < 32 ) {
+ chr += 64;
+ }
+ putchar( chr );
+ chr = ( y ) & 077;
+ if ( chr < 32 ) {
+ chr += 64;
+ }
+ putchar( chr );
+ return;
+}
+
+putMBN( i )
+ int i;
+{
+ int chr;
+
+ chr = ( i>>12 ) & 07;
+ chr|= 0140;
+ putchar( chr );
+ chr = ( i>>6 ) & 077;
+ if ( chr < 32 ) {
+ chr += 64;
+ }
+ putchar( chr );
+ chr = i & 077;
+ if ( chr < 32 ) {
+ chr += 64;
+ }
+ putchar( chr );
+ return;
+}
+
+putSBN( i )
+ int i;
+{
+ i &= 077;
+ if ( i < 32 ) {
+ i += 64;
+ }
+ putchar( i );
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/Makefile b/usr/src/ucbcmd/plot/libplot/imagen/Makefile
new file mode 100644
index 0000000000..a82b75d914
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/Makefile
@@ -0,0 +1,57 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+DEFRES = 240
+
+LIBRARY= ../libimagen.a
+
+OBJECTS = arc.o box.o charset.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o scale.o space.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+CPPFLAGS += -DDEFRES=$(DEFRES)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/arc.c b/usr/src/ucbcmd/plot/libplot/imagen/arc.c
new file mode 100644
index 0000000000..35e2d3f440
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/arc.c
@@ -0,0 +1,127 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+int del = 20;
+step(d){
+ del = d;
+}
+arc(x,y,x0,y0,x1,y1){
+ double pc;
+ double sqrt();
+ int flg,m,xc,yc,xs,ys,qs,qf;
+ float dx,dy,r;
+ char use;
+ dx = x-x0;
+ dy = y-y0;
+ r = dx*dx+dy*dy;
+ pc = r;
+ pc = sqrt(pc);
+ flg = pc/4;
+ if(flg == 0)step(1);
+ else if(flg < del)step(flg);
+ xc = xs = x0;
+ yc = ys = y0;
+ move(xs,ys);
+ if(x0 == x1 && y0 == y1)flg=0;
+ else flg=1;
+ qs = quad(x,y,x0,y0);
+ qf = quad(x,y,x1,y1);
+ if(abs(x-x1) < abs(y-y1)){
+ use = 'x';
+ if(qs == 2 || qs ==3)m = -1;
+ else m=1;
+ }
+ else {
+ use = 'y';
+ if(qs > 2)m= -1;
+ else m= 1;
+ }
+ while(1){
+ switch(use){
+ case 'x':
+ if(qs == 2 || qs == 3)yc -= del;
+ else yc += del;
+ dy = yc-y;
+ pc = r-dy*dy;
+ xc = m*sqrt(pc)+x;
+ if((x < xs && x >= xc) || ( x > xs && x <= xc) ||
+ (y < ys && y >= yc) || ( y > ys && y <= yc) )
+ {
+ if(++qs > 4)qs=1;
+ if(qs == 2 || qs == 3)m= -1;
+ else m=1;
+ flg=1;
+ }
+ cont(xc,yc);
+ xs = xc;
+ ys = yc;
+ if(qs == qf && flg == 1)
+ switch(qf){
+ case 3:
+ case 4:
+ if(xs >= x1)return;
+ continue;
+ case 1:
+ case 2:
+ if(xs <= x1)return;
+ }
+ continue;
+ case 'y':
+ if(qs > 2)xc += del;
+ else xc -= del;
+ dx = xc-x;
+ pc = r-dx*dx;
+ yc = m*sqrt(pc)+y;
+ if((x < xs && x >= xc) || ( x > xs && x <= xc ) ||
+ (y < ys && y >= yc) || (y > ys && y <= yc) )
+ {
+ if(++qs > 4)qs=1;
+ if(qs > 2)m = -1;
+ else m = 1;
+ flg=1;
+ }
+ cont(xc,yc);
+ xs = xc;
+ ys = yc;
+ if(qs == qf && flg == 1)
+ switch(qs){
+ case 1:
+ case 4:
+ if(ys >= y1)return;
+ continue;
+ case 2:
+ case 3:
+ if(ys <= y1)return;
+ }
+ }
+ }
+}
+quad(x,y,xp,yp){
+ if(x < xp)
+ if(y <= yp)return(1);
+ else return(4);
+ else if(x > xp)
+ if(y < yp)return(2);
+ else return(3);
+ else if(y < yp)return(2);
+ else return(4);
+}
+abs(a){
+ if(a < 0)return(-a);
+ return(a);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/box.c b/usr/src/ucbcmd/plot/libplot/imagen/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/charset.c b/usr/src/ucbcmd/plot/libplot/imagen/charset.c
new file mode 100644
index 0000000000..5beefed61a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/charset.c
@@ -0,0 +1,21 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imp.h"
+char *imP_charset = "cour07";
+int imPcsize = 12;
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/circle.c b/usr/src/ucbcmd/plot/libplot/imagen/circle.c
new file mode 100644
index 0000000000..45bbe8bdf5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/circle.c
@@ -0,0 +1,21 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+circle(x,y,r){
+ arc(x,y,x+r,y,x+r,y);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/close.c b/usr/src/ucbcmd/plot/libplot/imagen/close.c
new file mode 100644
index 0000000000..d5c38e003b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/close.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imp.h"
+#include "imPcodes.h"
+
+closepl(){
+ putch(imP_ENDPAGE);
+ fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/cont.c b/usr/src/ucbcmd/plot/libplot/imagen/cont.c
new file mode 100644
index 0000000000..f1d0c783d1
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/cont.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+#include "imp.h"
+
+cont(x,y){
+ line(imPx, imPy, x, y);
+
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/dot.c b/usr/src/ucbcmd/plot/libplot/imagen/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/erase.c b/usr/src/ucbcmd/plot/libplot/imagen/erase.c
new file mode 100644
index 0000000000..7e6403fe48
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/erase.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imPcodes.h"
+#include "imp.h"
+erase(){
+ int i;
+ putch(imP_ENDPAGE);
+ imPx = imPy = 0;
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/imPcodes.h b/usr/src/ucbcmd/plot/libplot/imagen/imPcodes.h
new file mode 100644
index 0000000000..ad67875602
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/imPcodes.h
@@ -0,0 +1,67 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1985 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#define imP_SP 128
+#define imP_SP1 129
+#define imP_OLD_MMOVE 130
+#define imP_MPLUS 131
+#define imP_MMINUS 132
+#define imP_MMOVE 133
+#define imP_SMOVE 134
+
+#define imP_SET_ABS_H 135
+#define imP_SET_REL_H 136
+#define imP_SET_ABS_V 137
+#define imP_SET_REL_V 138
+
+#define imP_SRULE 192
+#define imP_BRULE 193
+
+#define imP_SET_HPOS 195
+#define imP_SET_VPOS 196
+#define imP_CRLF 197
+#define imP_SGLY 198
+#define imP_BGLY 199
+#define imP_DELG 200
+#define imP_DELC 201
+#define imP_DELF 202
+
+#define imP_SET_HV_SYSTEM 205
+#define imP_SET_ADV_DIRS 206
+#define imP_SET_FAMILY 207
+#define imP_SET_IL 208
+#define imP_SET_BOL 209
+#define imP_SET_SP 210
+#define imP_PUSH 211
+#define imP_POP 212
+#define imP_PAGE 213
+#define imP_SET_PUSH_MASK 214
+#define imP_ENDPAGE 219
+
+#define imP_CREATE_FAMILY_TABLE 221
+#define imP_CREATE_MAP 222
+
+#define imP_CREATE_PATH 230
+#define imP_SET_TEXTURE 231
+#define imP_SET_PEN 232
+#define imP_FILL_PATH 233
+#define imP_DRAW_PATH 234
+#define imP_BITMAP 235
+#define imP_SET_MAGN 236
+
+#define imP_EOF 255
+
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/imp.h b/usr/src/ucbcmd/plot/libplot/imagen/imp.h
new file mode 100644
index 0000000000..af8a814dba
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/imp.h
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1985 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#include <stdio.h>
+extern float obotx;
+extern float boty;
+extern float botx;
+extern float oboty;
+extern float scalex;
+extern float scaley;
+int imPx, imPy;
+extern int imPcsize;
+extern char *imP_charset;
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/label.c b/usr/src/ucbcmd/plot/libplot/imagen/label.c
new file mode 100644
index 0000000000..a25b4711ae
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/label.c
@@ -0,0 +1,35 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imPcodes.h"
+#include "imp.h"
+extern imPcsize;
+label(s)
+char *s;
+{
+ register i,c;
+ putch(imP_SET_ABS_H);
+ putwd((int)((imPx-obotx)*scalex+botx)-imPcsize/2);
+ putch(imP_SET_ABS_V);
+ putwd((int)((imPy-oboty)*scaley+boty-(imPcsize/1.6)));
+ for(i=0; c=s[i]; i++)
+ {
+ imPx += imPcsize/scalex;
+ putch((c == ' ')?imP_SP:c);
+ }
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/line.c b/usr/src/ucbcmd/plot/libplot/imagen/line.c
new file mode 100644
index 0000000000..0a90fa6a57
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/line.c
@@ -0,0 +1,48 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imp.h"
+#include "imPcodes.h"
+float obotx = 0.;
+float oboty = 0.;
+float botx = 2.;
+float boty = 2.;
+float scalex = 1.;
+float scaley = 1.;
+line(x0,y0,x1,y1)
+{
+ putch(imP_CREATE_PATH);
+ putwd(2); /* two coordinates follow */
+ putwd((int)((x0-obotx)*scalex+botx));
+ putwd((int)((y0-oboty)*scaley+boty));
+ putwd((int)((x1-obotx)*scalex+botx));
+ putwd((int)((y1-oboty)*scaley+boty));
+ putch(imP_DRAW_PATH);
+ putch(15); /* "black" lines */
+ imPx = x1;
+ imPy = y1;
+}
+putch(c)
+{
+ putc(c, stdout);
+}
+putwd(w)
+{
+ putch(w>>8);
+ putch(w);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/linemod.c b/usr/src/ucbcmd/plot/libplot/imagen/linemod.c
new file mode 100644
index 0000000000..9ba7b31ef9
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/linemod.c
@@ -0,0 +1,50 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imp.h"
+
+/*
+ * Hack to set font.
+ */
+linemod(s)
+char *s;
+{
+ register char *tit;
+ register char *nam;
+ int siz = 0;
+ nam = s;
+ for(tit = "charset="; *tit; )
+ if (*tit++ != *nam++)
+ return;
+ s = nam;
+ while(*nam)
+ switch(*nam++) {
+ case ',':
+ case '\n':
+ *--nam = 0;
+ }
+ siz = atoi(++nam);
+ if (siz == 0) {
+ while (*--nam >= '0' && *nam <= '9')
+ ;
+ siz = (atoi(++nam)*4)/3;
+ }
+ if (siz == 0)
+ siz = imPcsize;
+ setfont(s, siz);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/move.c b/usr/src/ucbcmd/plot/libplot/imagen/move.c
new file mode 100644
index 0000000000..ea954ebd18
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/move.c
@@ -0,0 +1,23 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imp.h"
+move(xi,yi){
+ imPx = xi;
+ imPy = yi;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/open.c b/usr/src/ucbcmd/plot/libplot/imagen/open.c
new file mode 100644
index 0000000000..4f51b9636c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/open.c
@@ -0,0 +1,49 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "imPcodes.h"
+#include "imp.h"
+
+openpl(){
+
+ putch(imP_SET_HV_SYSTEM);
+ putch((3<<3)|5);
+ putch(imP_SET_FAMILY);
+ putch(2);
+ setfont(imP_charset,imPcsize);
+ putch(imP_SET_IL);
+ putwd(imPcsize+3);
+ putch(imP_SET_SP);
+ putwd(imPcsize);
+ putch(imP_SET_PEN);
+ putch(2);
+ putch(imP_SET_ABS_H);
+ putwd(0);
+ putch(imP_SET_ABS_V);
+ putwd(0);
+}
+setfont(c, sz) char *c; int sz;
+{
+ imPcsize = sz;
+ putch(imP_CREATE_FAMILY_TABLE);
+ putch(2);
+ putch(1);
+ putch(0);
+ fprintf(stdout, c);
+ putch(0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/point.c b/usr/src/ucbcmd/plot/libplot/imagen/point.c
new file mode 100644
index 0000000000..21e7bde131
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/point.c
@@ -0,0 +1,21 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+point(xi,yi){
+ line(xi,yi,xi,yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/scale.c b/usr/src/ucbcmd/plot/libplot/imagen/scale.c
new file mode 100644
index 0000000000..5311f551fe
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/scale.c
@@ -0,0 +1,40 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+extern float scalex;
+extern float scaley;
+extern int scaleflag;
+scale(i,x,y)
+char i;
+float x,y;
+{
+ switch(i) {
+ default:
+ return;
+ case 'c':
+ x *= 2.54;
+ y *= 2.54;
+ case 'i':
+ x /= 200;
+ y /= 200;
+ case 'u':
+ scalex = 1/x;
+ scaley = 1/y;
+ }
+ scaleflag = 1;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/imagen/space.c b/usr/src/ucbcmd/plot/libplot/imagen/space.c
new file mode 100644
index 0000000000..cf600c906a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/imagen/space.c
@@ -0,0 +1,38 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+extern float botx;
+extern float boty;
+extern float obotx;
+extern float oboty;
+extern float scalex;
+extern float scaley;
+
+int PlotRes = DEFRES;
+
+int scaleflag;
+space(x0,y0,x1,y1){
+ botx = 2.;
+ boty = 2.;
+ obotx = x0;
+ oboty = y0;
+ if(scaleflag)
+ return;
+ scalex = (8.0 * PlotRes)/(x1-x0);
+ scaley = (8.0 * PlotRes)/(y1-y0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/Makefile b/usr/src/ucbcmd/plot/libplot/plot/Makefile
new file mode 100644
index 0000000000..50ee27fc43
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libplot.a
+
+OBJECTS = arc.o box.o circle.o close.o cont.o dot.o erase.o label.o \
+ line.o linmod.o move.o open.o point.o putsi.o space.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/plot/arc.c b/usr/src/ucbcmd/plot/libplot/plot/arc.c
new file mode 100644
index 0000000000..91ef25c467
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/arc.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+arc(xi,yi,x0,y0,x1,y1){
+ putc('a',stdout);
+ putsi(xi);
+ putsi(yi);
+ putsi(x0);
+ putsi(y0);
+ putsi(x1);
+ putsi(y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/box.c b/usr/src/ucbcmd/plot/libplot/plot/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/circle.c b/usr/src/ucbcmd/plot/libplot/plot/circle.c
new file mode 100644
index 0000000000..f32522b9c8
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/circle.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+circle(x,y,r){
+ putc('c',stdout);
+ putsi(x);
+ putsi(y);
+ putsi(r);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/close.c b/usr/src/ucbcmd/plot/libplot/plot/close.c
new file mode 100644
index 0000000000..fd34f94b2b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/close.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+closevt(){
+ fflush(stdout);
+}
+closepl(){
+ fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/cont.c b/usr/src/ucbcmd/plot/libplot/plot/cont.c
new file mode 100644
index 0000000000..970e6d5803
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/cont.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+cont(xi,yi){
+ putc('n',stdout);
+ putsi(xi);
+ putsi(yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/dot.c b/usr/src/ucbcmd/plot/libplot/plot/dot.c
new file mode 100644
index 0000000000..8fb1610972
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/dot.c
@@ -0,0 +1,30 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+dot(xi,yi,dx,n,pat)
+int pat[];
+{
+ int i;
+ putc('d',stdout);
+ putsi(xi);
+ putsi(yi);
+ putsi(dx);
+ putsi(n);
+ for(i=0; i<n; i++)putsi(pat[i]);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/erase.c b/usr/src/ucbcmd/plot/libplot/plot/erase.c
new file mode 100644
index 0000000000..059fe9aae1
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/erase.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+erase(){
+ putc('e',stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/label.c b/usr/src/ucbcmd/plot/libplot/plot/label.c
new file mode 100644
index 0000000000..cd345bf74d
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/label.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+label(s)
+char *s;
+{
+ int i;
+ putc('t',stdout);
+ for(i=0;s[i];)putc(s[i++],stdout);
+ putc('\n',stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/line.c b/usr/src/ucbcmd/plot/libplot/plot/line.c
new file mode 100644
index 0000000000..7885631956
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/line.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+line(x0,y0,x1,y1){
+ putc('l',stdout);
+ putsi(x0);
+ putsi(y0);
+ putsi(x1);
+ putsi(y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/linmod.c b/usr/src/ucbcmd/plot/libplot/plot/linmod.c
new file mode 100644
index 0000000000..e5906e292e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/linmod.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+linemod(s)
+char *s;
+{
+ int i;
+ putc('f',stdout);
+ for(i=0;s[i];)putc(s[i++],stdout);
+ putc('\n',stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/move.c b/usr/src/ucbcmd/plot/libplot/plot/move.c
new file mode 100644
index 0000000000..06f3456f4d
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/move.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+move(xi,yi){
+ putc('m',stdout);
+ putsi(xi);
+ putsi(yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/open.c b/usr/src/ucbcmd/plot/libplot/plot/open.c
new file mode 100644
index 0000000000..fbfa68f015
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/open.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+openvt(){
+}
+openpl(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/point.c b/usr/src/ucbcmd/plot/libplot/plot/point.c
new file mode 100644
index 0000000000..2d515b7f25
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/point.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+point(xi,yi){
+ putc('p',stdout);
+ putsi(xi);
+ putsi(yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/putsi.c b/usr/src/ucbcmd/plot/libplot/plot/putsi.c
new file mode 100644
index 0000000000..04364105ab
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/putsi.c
@@ -0,0 +1,23 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+putsi(a){
+ putc((char)a,stdout);
+ putc((char)(a>>8),stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/plot/space.c b/usr/src/ucbcmd/plot/libplot/plot/space.c
new file mode 100644
index 0000000000..ca4f8693e9
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/plot/space.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+space(x0,y0,x1,y1){
+ putc('s',stdout);
+ putsi(x0);
+ putsi(y0);
+ putsi(x1);
+ putsi(y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/Makefile b/usr/src/ucbcmd/plot/libplot/t300/Makefile
new file mode 100644
index 0000000000..47acf8ffe0
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libt300.a
+
+OBJECTS = arc.o box.o circle.o close.o dot.o erase.o label.o \
+ line.o linmod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/t300/arc.c b/usr/src/ucbcmd/plot/libplot/t300/arc.c
new file mode 100644
index 0000000000..a4d5e23fde
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/arc.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+arc(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/box.c b/usr/src/ucbcmd/plot/libplot/t300/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/circle.c b/usr/src/ucbcmd/plot/libplot/t300/circle.c
new file mode 100644
index 0000000000..bb9a06ff21
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/circle.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+circle(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/close.c b/usr/src/ucbcmd/plot/libplot/t300/close.c
new file mode 100644
index 0000000000..cfbbcbf520
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/close.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+closevt(){
+ closepl();
+}
+closepl(){
+ fflush(stdout);
+ reset();
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/con.h b/usr/src/ucbcmd/plot/libplot/t300/con.h
new file mode 100644
index 0000000000..0476248c6f
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/con.h
@@ -0,0 +1,37 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include <sgtty.h>
+/* gsi plotting output routines */
+# define DOWN 012
+# define UP 013
+# define LEFT 010
+# define RIGHT 040
+# define BEL 007
+# define ESC 033
+# define ACK 006
+# define CR 015
+# define FF 014
+# define VERTRESP 48
+# define HORZRESP 60.
+# define VERTRES 8.
+# define HORZRES 6.
+/* down is line feed, up is reverse line feed,
+ left is backspace, right is space. 48 points per inch
+ vertically, 60 horizontally */
+
+extern int xnow, ynow;
+extern int OUTF;
+extern struct sgttyb ITTY, PTTY;
+extern float HEIGHT, WIDTH, OFFSET;
+extern int xscale, xoffset, yscale;
+extern float botx, boty, obotx, oboty, scalex,scaley;
+
diff --git a/usr/src/ucbcmd/plot/libplot/t300/dot.c b/usr/src/ucbcmd/plot/libplot/t300/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/erase.c b/usr/src/ucbcmd/plot/libplot/t300/erase.c
new file mode 100644
index 0000000000..44fbab553e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/erase.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "con.h"
+erase(){
+ int i;
+ for(i=0; i<11*(VERTRESP/VERTRES); i++)
+ spew(DOWN);
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/label.c b/usr/src/ucbcmd/plot/libplot/t300/label.c
new file mode 100644
index 0000000000..4bd61984a6
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/label.c
@@ -0,0 +1,29 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "con.h"
+label(s)
+char *s;
+{
+ int i,c;
+ while((c = *s++) != '\0'){
+ xnow += 6;
+ spew(c);
+ }
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/line.c b/usr/src/ucbcmd/plot/libplot/t300/line.c
new file mode 100644
index 0000000000..9cca61858e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/line.c
@@ -0,0 +1,63 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "con.h"
+line(x0,y0,x1,y1){
+ iline(xconv(xsc(x0)),yconv(ysc(y0)),xconv(xsc(x1)),yconv(ysc(y1)));
+ return;
+}
+cont(x0,y0){
+ iline(xnow,ynow,xconv(xsc(x0)),yconv(ysc(y0)));
+ return;
+}
+iline(cx0,cy0,cx1,cy1){
+ int maxp,tt,j,np;
+ char chx,chy;
+ float xd,yd;
+ float dist2(),sqrt();
+ movep(cx0,cy0);
+ maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.;
+ xd = cx1-cx0;
+ yd = cy1-cy0;
+ if(xd >= 0)chx = RIGHT;
+ else chx = LEFT;
+ if(yd >= 0)chy = UP;
+ else chy = DOWN;
+ if(maxp==0){
+ xd=0;
+ yd=0;
+ }
+ else{
+ xd /= maxp;
+ yd /= maxp;
+ }
+ inplot();
+ for (tt=0; tt<=maxp; tt++){
+ j= cx0+xd*tt-xnow;
+ xnow += j;
+ j = abval(j);
+ while(j-- > 0)spew(chx);
+ j = cy0+yd*tt-ynow;
+ ynow += j;
+ j = abval(j);
+ while(j-- > 0)spew(chy);
+ spew ('.');
+ }
+ outplot();
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/linmod.c b/usr/src/ucbcmd/plot/libplot/t300/linmod.c
new file mode 100644
index 0000000000..46a98ef7ff
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/linmod.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+linemod(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/move.c b/usr/src/ucbcmd/plot/libplot/t300/move.c
new file mode 100644
index 0000000000..0c67496c4c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/move.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+move(xi,yi){
+ movep(xconv(xsc(xi)),yconv(ysc(yi)));
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/open.c b/usr/src/ucbcmd/plot/libplot/t300/open.c
new file mode 100644
index 0000000000..ce326d4dea
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/open.c
@@ -0,0 +1,65 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#
+#include <sgtty.h>
+/* gsi plotting output routines */
+# define DOWN 012
+# define UP 013
+# define LEFT 010
+# define RIGHT 040
+# define BEL 007
+# define ACK 006
+# define CR 015
+# define FF 014
+# define VERTRESP 48
+# define HORZRESP 60.
+# define HORZRES 6.
+# define VERTRES 8.
+/* down is line feed, up is reverse oyne feed,
+ left is bwckspace, right is space. 48 points per inch
+ vertically, 60 horizontally */
+
+int xnow, ynow;
+int OUTF;
+struct sgttyb ITTY, PTTY;
+float HEIGHT = 6.0, WIDTH = 6.0, OFFSET = 0.0;
+int xscale, xoffset, yscale;
+float botx = 0., boty = 0., obotx = 0., oboty = 0.;
+float scalex = 1., scaley = 1.;
+
+openpl ()
+{
+ int reset();
+ xnow = ynow = 0;
+ OUTF = 1;
+ printf("\r");
+ gtty(OUTF, &ITTY);
+ signal (2, reset);
+ PTTY = ITTY;
+ PTTY.sg_flags &= ~CRMOD; /* don't map lf */
+ /* initialize constants */
+ xscale = 4096./(HORZRESP * WIDTH);
+ yscale = 4096 /(VERTRESP * HEIGHT);
+ xoffset = OFFSET * HORZRESP;
+ return;
+}
+
+openvt(){
+openpl();
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/point.c b/usr/src/ucbcmd/plot/libplot/t300/point.c
new file mode 100644
index 0000000000..f0d9baab1b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/point.c
@@ -0,0 +1,23 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+point(xi,yi){
+ move(xi,yi);
+ label(".");
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/space.c b/usr/src/ucbcmd/plot/libplot/t300/space.c
new file mode 100644
index 0000000000..d8df66c6ce
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/space.c
@@ -0,0 +1,29 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+# include "con.h"
+float deltx = 4095.;
+float delty = 4095.;
+space(x0,y0,x1,y1){
+ botx = -2047.;
+ boty = -2047.;
+ obotx = x0;
+ oboty = y0;
+ scalex = deltx/(x1-x0);
+ scaley = delty/(y1-y0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300/subr.c b/usr/src/ucbcmd/plot/libplot/t300/subr.c
new file mode 100644
index 0000000000..27b5591d8b
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300/subr.c
@@ -0,0 +1,130 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+#include "con.h"
+abval(q)
+{
+ return (q>=0 ? q : -q);
+}
+
+xconv (xp)
+{
+ /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */
+ xp += 2048;
+ /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
+ return (xoffset + xp /xscale);
+}
+
+yconv (yp)
+{
+ /* see description of xconv */
+ yp += 2048;
+ return (yp / yscale);
+}
+
+inplot()
+{
+ stty(OUTF, &PTTY);
+ spew (ACK);
+}
+
+outplot()
+{
+ spew(ESC);
+ spew(ACK);
+ fflush(stdout);
+ stty(OUTF, &ITTY);
+}
+
+spew(ch)
+{
+ if(ch == UP)putc(ESC,stdout);
+ putc(ch, stdout);
+}
+
+tobotleft ()
+{
+ move(-2048,-2048);
+}
+reset()
+{
+ outplot();
+ exit(0);
+}
+
+float
+dist2 (x1, y1, x2, y2)
+{
+ float t,v;
+ t = x2-x1;
+ v = y1-y2;
+ return (t*t+v*v);
+}
+
+swap (pa, pb)
+int *pa, *pb;
+{
+ int t;
+ t = *pa;
+ *pa = *pb;
+ *pb = t;
+}
+movep (xg, yg)
+{
+ int i,ch;
+ if((xg == xnow) && (yg == ynow))return;
+ /* if we need to go to left margin, just CR */
+ if (xg < xnow/2)
+ {
+ spew(CR);
+ xnow = 0;
+ }
+ i = (xg-xnow)/HORZRES;
+ if(xnow < xg)ch = RIGHT;
+ else ch = LEFT;
+ xnow += i*HORZRES;
+ i = abval(i);
+ while(i--)spew(ch);
+ i = abval(xg-xnow);
+ inplot();
+ while(i--) spew(ch);
+ outplot();
+ i=(yg-ynow)/VERTRES;
+ if(ynow < yg)ch = UP;
+ else ch = DOWN;
+ ynow += i*VERTRES;
+ i = abval(i);
+ while(i--)spew(ch);
+ i=abval(yg-ynow);
+ inplot();
+ while(i--)spew(ch);
+ outplot();
+ xnow = xg; ynow = yg;
+}
+
+xsc(xi){
+ int xa;
+ xa = (xi - obotx) * scalex + botx;
+ return(xa);
+}
+ysc(yi){
+ int ya;
+ ya = (yi - oboty) *scaley +boty;
+ return(ya);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/Makefile b/usr/src/ucbcmd/plot/libplot/t300s/Makefile
new file mode 100644
index 0000000000..d7eaf02d04
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libt300s.a
+
+OBJECTS = arc.o box.o circle.o close.o dot.o erase.o label.o \
+ line.o linmod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/arc.c b/usr/src/ucbcmd/plot/libplot/t300s/arc.c
new file mode 100644
index 0000000000..a4d5e23fde
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/arc.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+arc(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/box.c b/usr/src/ucbcmd/plot/libplot/t300s/box.c
new file mode 100644
index 0000000000..fe42272269
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/box.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/circle.c b/usr/src/ucbcmd/plot/libplot/t300s/circle.c
new file mode 100644
index 0000000000..bb9a06ff21
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/circle.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+circle(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/close.c b/usr/src/ucbcmd/plot/libplot/t300s/close.c
new file mode 100644
index 0000000000..cfbbcbf520
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/close.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+closevt(){
+ closepl();
+}
+closepl(){
+ fflush(stdout);
+ reset();
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/con.h b/usr/src/ucbcmd/plot/libplot/t300s/con.h
new file mode 100644
index 0000000000..75ed00c49e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/con.h
@@ -0,0 +1,46 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#
+#include <sgtty.h>
+/* gsi plotting output routines */
+# define DOUBLE 010
+#define ADDR 0100
+#define COM 060
+#define PENUP 04
+#define MAXX 070
+#define MAXY 07
+#define SPACES 7
+# define DOWN 012
+# define UP 013
+# define LEFT 010
+# define RIGHT 040
+# define BEL 007
+# define ESC 033
+# define ACK 006
+# define INPLOT 'P'
+# define CR 015
+# define FF 014
+# define VERTRESP 48
+# define HORZRESP 60.
+# define VERTRES 8.
+# define HORZRES 6.
+/* down is line feed, up is reverse line feed,
+ left is backspace, right is space. 48 points per inch
+ vertically, 60 horizontally */
+
+extern int xnow, ynow;
+extern int OUTF;
+extern struct sgttyb ITTY, PTTY;
+extern float HEIGHT, WIDTH, OFFSET;
+extern int xscale, xoffset, yscale;
+extern float botx, boty, obotx, oboty, scalex,scaley;
+
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/dot.c b/usr/src/ucbcmd/plot/libplot/t300s/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/erase.c b/usr/src/ucbcmd/plot/libplot/t300s/erase.c
new file mode 100644
index 0000000000..44fbab553e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/erase.c
@@ -0,0 +1,25 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "con.h"
+erase(){
+ int i;
+ for(i=0; i<11*(VERTRESP/VERTRES); i++)
+ spew(DOWN);
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/label.c b/usr/src/ucbcmd/plot/libplot/t300s/label.c
new file mode 100644
index 0000000000..325e4c06dd
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/label.c
@@ -0,0 +1,29 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "con.h"
+label(s)
+char *s;
+{
+ int i,c;
+ while((c = *s++) != '\0'){
+ xnow += HORZRES;
+ spew(c);
+ }
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/line.c b/usr/src/ucbcmd/plot/libplot/t300s/line.c
new file mode 100644
index 0000000000..5a6179c3aa
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/line.c
@@ -0,0 +1,59 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "con.h"
+line(x0,y0,x1,y1){
+ iline(xconv(xsc(x0)),yconv(ysc(y0)),xconv(xsc(x1)),yconv(ysc(y1)));
+ return;
+}
+cont(x0,y0){
+ iline(xnow,ynow,xconv(xsc(x0)),yconv(ysc(y0)));
+ return;
+}
+iline(cx0,cy0,cx1,cy1){
+ int maxp,tt,j,np;
+ char chx,chy,command;
+ float xd,yd;
+ float dist2(),sqrt();
+ movep(cx0,cy0);
+ maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.;
+ xd = cx1-cx0;
+ yd = cy1-cy0;
+ command = COM|((xd<0)<<1)|(yd<0);
+ if(maxp == 0){
+ xd=0;
+ yd=0;
+ }
+ else {
+ xd /= maxp;
+ yd /= maxp;
+ }
+ inplot();
+ spew(command);
+ for (tt=0; tt<=maxp; tt++){
+ chx= cx0+xd*tt-xnow;
+ xnow += chx;
+ chx = abval(chx);
+ chy = cy0+yd*tt-ynow;
+ ynow += chy;
+ chy = abval(chy);
+ spew(ADDR|chx<<3|chy);
+ }
+ outplot();
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/linmod.c b/usr/src/ucbcmd/plot/libplot/t300s/linmod.c
new file mode 100644
index 0000000000..46a98ef7ff
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/linmod.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+linemod(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/move.c b/usr/src/ucbcmd/plot/libplot/t300s/move.c
new file mode 100644
index 0000000000..0c67496c4c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/move.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+move(xi,yi){
+ movep(xconv(xsc(xi)),yconv(ysc(yi)));
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/open.c b/usr/src/ucbcmd/plot/libplot/t300s/open.c
new file mode 100644
index 0000000000..ce326d4dea
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/open.c
@@ -0,0 +1,65 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#
+#include <sgtty.h>
+/* gsi plotting output routines */
+# define DOWN 012
+# define UP 013
+# define LEFT 010
+# define RIGHT 040
+# define BEL 007
+# define ACK 006
+# define CR 015
+# define FF 014
+# define VERTRESP 48
+# define HORZRESP 60.
+# define HORZRES 6.
+# define VERTRES 8.
+/* down is line feed, up is reverse oyne feed,
+ left is bwckspace, right is space. 48 points per inch
+ vertically, 60 horizontally */
+
+int xnow, ynow;
+int OUTF;
+struct sgttyb ITTY, PTTY;
+float HEIGHT = 6.0, WIDTH = 6.0, OFFSET = 0.0;
+int xscale, xoffset, yscale;
+float botx = 0., boty = 0., obotx = 0., oboty = 0.;
+float scalex = 1., scaley = 1.;
+
+openpl ()
+{
+ int reset();
+ xnow = ynow = 0;
+ OUTF = 1;
+ printf("\r");
+ gtty(OUTF, &ITTY);
+ signal (2, reset);
+ PTTY = ITTY;
+ PTTY.sg_flags &= ~CRMOD; /* don't map lf */
+ /* initialize constants */
+ xscale = 4096./(HORZRESP * WIDTH);
+ yscale = 4096 /(VERTRESP * HEIGHT);
+ xoffset = OFFSET * HORZRESP;
+ return;
+}
+
+openvt(){
+openpl();
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/point.c b/usr/src/ucbcmd/plot/libplot/t300s/point.c
new file mode 100644
index 0000000000..65188fd162
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/point.c
@@ -0,0 +1,24 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include "con.h"
+point(xi,yi){
+ move(xi,yi);
+ label(".");
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/space.c b/usr/src/ucbcmd/plot/libplot/t300s/space.c
new file mode 100644
index 0000000000..78c1836578
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/space.c
@@ -0,0 +1,28 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+# include "con.h"
+float deltx = 4095.;
+float delty = 4095.;
+space(x0,y0,x1,y1){
+ botx = -2047.;
+ boty = -2047.;
+ obotx = x0;
+ oboty = y0;
+ scalex = deltx/(x1-x0);
+ scaley = delty/(y1-y0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t300s/subr.c b/usr/src/ucbcmd/plot/libplot/t300s/subr.c
new file mode 100644
index 0000000000..2d54112f1c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t300s/subr.c
@@ -0,0 +1,174 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+#include "con.h"
+abval(q)
+{
+ return (q>=0 ? q : -q);
+}
+
+xconv (xp)
+{
+ /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */
+ xp += 2048;
+ /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
+ return (xoffset + xp /xscale);
+}
+
+yconv (yp)
+{
+ /* see description of xconv */
+ yp += 2048;
+ return (yp / yscale);
+}
+
+inplot()
+{
+ stty(OUTF, &PTTY);
+ spew(ESC);
+ spew (INPLOT);
+}
+
+outplot()
+{
+ spew(ESC);
+ spew(ACK);
+ spew(ESC);
+ spew(ACK);
+ fflush(stdout);
+ stty (OUTF, &ITTY);
+}
+
+spew(ch)
+{
+ putc(ch, stdout);
+}
+
+tobotleft ()
+{
+ move(-2048,-2048);
+}
+reset()
+{
+ outplot();
+ exit(0);
+}
+
+float
+dist2 (x1, y1, x2, y2)
+{
+ float t,v;
+ t = x2-x1;
+ v = y1-y2;
+ return (t*t+v*v);
+}
+
+swap (pa, pb)
+int *pa, *pb;
+{
+ int t;
+ t = *pa;
+ *pa = *pb;
+ *pb = t;
+}
+
+#define DOUBLE 010
+#define ADDR 0100
+#define COM 060
+#define MAXX 070
+#define MAXY 07
+extern xnow,ynow;
+#define SPACES 7
+movep(ix,iy){
+ int dx,dy,remx,remy,pts,i;
+ int xd,yd;
+ int addr,command;
+ char c;
+ if(xnow == ix && ynow == iy)return;
+ inplot();
+ dx = ix-xnow;
+ dy = iy-ynow;
+ command = COM|PENUP|((dx<0)<<1)|(dy<0);
+ dx = abval(dx);
+ dy = abval(dy);
+ xd = dx/(SPACES*2);
+ yd = dy/(SPACES*2);
+ pts = xd<yd?xd:yd;
+ if((i=pts)>0){
+ c=command|DOUBLE;
+ addr=ADDR;
+ if(xd>0)addr|=MAXX;
+ if(yd>0)addr|=MAXY;
+ spew(c);
+ while(i--){
+ spew(addr);
+ }
+ }
+ if(xd!=yd){
+ if(xd>pts){
+ i=xd-pts;
+ addr=ADDR|MAXX;
+ }
+ else{
+ i=yd-pts;
+ addr=ADDR|MAXY;
+ }
+ c=command|DOUBLE;
+ spew(c);
+ while(i--){
+ spew(addr);
+ }
+ }
+ remx=dx-xd*SPACES*2;
+ remy=dy-yd*SPACES*2;
+ addr=ADDR;
+ i = 0;
+ if(remx>7){
+ i=1;
+ addr|=MAXX;
+ remx -= 7;
+ }
+ if(remy>7){
+ i=1;
+ addr|=MAXY;
+ remy -= 7;
+ }
+ while(i--){
+ spew(command);
+ spew(addr);
+ }
+ if(remx>0||remy>0){
+ spew(command);
+ spew(ADDR|remx<<3|remy);
+ }
+ xnow=ix;
+ ynow=iy;
+ outplot();
+ return;
+}
+xsc(xi){
+ int xa;
+ xa = (xi - obotx) * scalex + botx;
+ return(xa);
+}
+ysc(yi){
+ int ya;
+ ya = (yi - oboty) *scaley +boty;
+ return(ya);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/Makefile b/usr/src/ucbcmd/plot/libplot/t4013/Makefile
new file mode 100644
index 0000000000..8d49aed2c4
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libt4013.a
+
+OBJECTS = arc.o box.o circle.o close.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/arc.c b/usr/src/ucbcmd/plot/libplot/t4013/arc.c
new file mode 100644
index 0000000000..69bb6f5697
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/arc.c
@@ -0,0 +1,122 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+int del = 20;
+step(d){
+ del = d;
+}
+arc(x,y,x0,y0,x1,y1){
+ double pc;
+ double sqrt();
+ int flg,m,xc,yc,xs,ys,qs,qf;
+ float dx,dy,r;
+ char use;
+ dx = x-x0;
+ dy = y-y0;
+ r = dx*dx+dy*dy;
+ pc = r;
+ pc = pc > 0 ? sqrt(pc) : 0;
+ flg = pc/4;
+ if(flg == 0)step(1);
+ else if(flg < del)step(flg);
+ xc = xs = x0;
+ yc = ys = y0;
+ move(xs,ys);
+ if(x0 == x1 && y0 == y1)flg=0;
+ else flg=1;
+ qs = quad(x,y,x0,y0);
+ qf = quad(x,y,x1,y1);
+ if(abs(x-x1) < abs(y-y1)){
+ use = 'x';
+ if(qs == 2 || qs ==3)m = -1;
+ else m=1;
+ }
+ else {
+ use = 'y';
+ if(qs > 2)m= -1;
+ else m= 1;
+ }
+ while(1){
+ switch(use){
+ case 'x':
+ if(qs == 2 || qs == 3)yc -= del;
+ else yc += del;
+ dy = yc-y;
+ pc = r-dy*dy;
+ xc = m*(pc > 0 ? sqrt(pc) : 0)+x;
+ if((x < xs && x >= xc) || ( x > xs && x <= xc) ||
+ (y < ys && y >= yc) || ( y > ys && y <= yc) )
+ {
+ if(++qs > 4)qs=1;
+ if(qs == 2 || qs == 3)m= -1;
+ else m=1;
+ flg=1;
+ }
+ cont(xc,yc);
+ xs = xc;
+ ys = yc;
+ if(qs == qf && flg == 1)
+ switch(qf){
+ case 3:
+ case 4:
+ if(xs >= x1)return;
+ continue;
+ case 1:
+ case 2:
+ if(xs <= x1)return;
+ }
+ continue;
+ case 'y':
+ if(qs > 2)xc += del;
+ else xc -= del;
+ dx = xc-x;
+ pc = r-dx*dx;
+ yc = m*(pc > 0 ? sqrt(pc) : 0)+y;
+ if((x < xs && x >= xc) || ( x > xs && x <= xc ) ||
+ (y < ys && y >= yc) || (y > ys && y <= yc) )
+ {
+ if(++qs > 4)qs=1;
+ if(qs > 2)m = -1;
+ else m = 1;
+ flg=1;
+ }
+ cont(xc,yc);
+ xs = xc;
+ ys = yc;
+ if(qs == qf && flg == 1)
+ switch(qs){
+ case 1:
+ case 4:
+ if(ys >= y1)return;
+ continue;
+ case 2:
+ case 3:
+ if(ys <= y1)return;
+ }
+ }
+ }
+}
+quad(x,y,xp,yp){
+ if(x < xp)
+ if(y <= yp)return(1);
+ else return(4);
+ else if(x > xp)
+ if(y < yp)return(2);
+ else return(3);
+ else if(y < yp)return(2);
+ else return(4);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/box.c b/usr/src/ucbcmd/plot/libplot/t4013/box.c
new file mode 100644
index 0000000000..ce721eefec
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/box.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/circle.c b/usr/src/ucbcmd/plot/libplot/t4013/circle.c
new file mode 100644
index 0000000000..45bbe8bdf5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/circle.c
@@ -0,0 +1,21 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+circle(x,y,r){
+ arc(x,y,x+r,y,x+r,y);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/close.c b/usr/src/ucbcmd/plot/libplot/t4013/close.c
new file mode 100644
index 0000000000..0d1d8256e0
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/close.c
@@ -0,0 +1,27 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+#include <stdio.h>
+closevt(){
+ putch(037);
+ fflush(stdout);
+}
+closepl(){
+ putch(037);
+ fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/dot.c b/usr/src/ucbcmd/plot/libplot/t4013/dot.c
new file mode 100644
index 0000000000..a9cf01dd0a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/dot.c
@@ -0,0 +1,20 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/erase.c b/usr/src/ucbcmd/plot/libplot/t4013/erase.c
new file mode 100644
index 0000000000..9f0a75482c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/erase.c
@@ -0,0 +1,30 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+extern int ohiy;
+extern int ohix;
+extern int oloy;
+erase(){
+ int i;
+ putch(033);
+ putch(014);
+ ohiy= -1;
+ ohix = -1;
+ oloy = -1;
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/label.c b/usr/src/ucbcmd/plot/libplot/t4013/label.c
new file mode 100644
index 0000000000..a4118a9e99
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/label.c
@@ -0,0 +1,26 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+label(s)
+char *s;
+{
+ register i,c;
+ putch(037); /* alpha mode */
+ for(i=0; c=s[i]; i++)
+ putch(c);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/line.c b/usr/src/ucbcmd/plot/libplot/t4013/line.c
new file mode 100644
index 0000000000..23bc2baccf
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/line.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+line(x0,y0,x1,y1){
+ move(x0,y0);
+ cont(x1,y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/linemod.c b/usr/src/ucbcmd/plot/libplot/t4013/linemod.c
new file mode 100644
index 0000000000..77d60374e4
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/linemod.c
@@ -0,0 +1,23 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+linemod(s)
+char *s;
+{
+ /* ignored on 4013 */
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/move.c b/usr/src/ucbcmd/plot/libplot/t4013/move.c
new file mode 100644
index 0000000000..a63a3f218a
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/move.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+move(xi,yi){
+ putch(035);
+ cont(xi,yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/open.c b/usr/src/ucbcmd/plot/libplot/t4013/open.c
new file mode 100644
index 0000000000..3b3a6f672c
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/open.c
@@ -0,0 +1,22 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+openvt ()
+{
+}
+openpl(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/point.c b/usr/src/ucbcmd/plot/libplot/t4013/point.c
new file mode 100644
index 0000000000..1e5393d5e5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/point.c
@@ -0,0 +1,21 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+point(xi,yi){
+ move(xi,yi);
+ cont(xi,yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/space.c b/usr/src/ucbcmd/plot/libplot/t4013/space.c
new file mode 100644
index 0000000000..3bc365d8c7
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/space.c
@@ -0,0 +1,34 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+extern float botx;
+extern float boty;
+extern float obotx;
+extern float oboty;
+extern float scalex;
+extern float scaley;
+extern int scaleflag;
+space(x0,y0,x1,y1){
+ botx = 0.;
+ boty = 0.;
+ obotx = x0;
+ oboty = y0;
+ if(scaleflag)
+ return;
+ scalex = 780./(x1-x0);
+ scaley = 780./(y1-y0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4013/subr.c b/usr/src/ucbcmd/plot/libplot/t4013/subr.c
new file mode 100644
index 0000000000..0772971b88
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4013/subr.c
@@ -0,0 +1,61 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#include <stdio.h>
+float obotx = 0.;
+float oboty = 0.;
+float botx = 0.;
+float boty = 0.;
+float scalex = 1.;
+float scaley = 1.;
+int scaleflag;
+
+int oloy = -1;
+int ohiy = -1;
+int ohix = -1;
+cont(x,y){
+ int hix,hiy,lox,loy;
+ int n;
+ x = (x-obotx)*scalex + botx;
+ y = (y-oboty)*scaley + boty;
+ hix=(x>>5) & 037;
+ hiy=(y>>5) & 037;
+ lox = x & 037;
+ loy = y & 037;
+ n = (abs(hix-ohix) + abs(hiy-ohiy) + 6) / 12;
+ if(hiy != ohiy){
+ putch(hiy|040);
+ ohiy=hiy;
+ }
+ if(hix != ohix){
+ putch(loy|0140);
+ putch(hix|040);
+ ohix=hix;
+ oloy=loy;
+ }
+ else if(loy != oloy){
+ putch(loy|0140);
+ oloy=loy;
+ }
+ putch(lox|0100);
+ while(n--)
+ putch(0);
+}
+
+putch(c){
+ putc(c,stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/Makefile b/usr/src/ucbcmd/plot/libplot/t4014/Makefile
new file mode 100644
index 0000000000..ad24feb0b4
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libt4014.a
+
+OBJECTS = arc.o box.o circle.o close.o dot.o erase.o label.o \
+ line.o linemod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/arc.c b/usr/src/ucbcmd/plot/libplot/t4014/arc.c
new file mode 100644
index 0000000000..a5ceb326d7
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/arc.c
@@ -0,0 +1,141 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+int del = 20;
+step(d){
+ del = d;
+}
+arc(x,y,x0,y0,x1,y1){
+ double pc;
+ double sqrt();
+ int flg,m,xc,yc,xs,ys,qs,qf;
+ float dx,dy,r;
+ char use;
+ dx = x-x0;
+ dy = y-y0;
+ r = dx*dx+dy*dy;
+ pc = r;
+ pc = sqrt(pc);
+ flg = pc/4;
+ if(flg == 0)step(1);
+ else if(flg < del)step(flg);
+ xc = xs = x0;
+ yc = ys = y0;
+ move(xs,ys);
+ if(x0 == x1 && y0 == y1)flg=0;
+ else flg=1;
+ qs = quad(x,y,x0,y0);
+ qf = quad(x,y,x1,y1);
+ if(abs(x-x1) < abs(y-y1)){
+ use = 'x';
+ if(qs == 2 || qs ==3)m = -1;
+ else m=1;
+ }
+ else {
+ use = 'y';
+ if(qs > 2)m= -1;
+ else m= 1;
+ }
+ while(1){
+ switch(use){
+ case 'x':
+ if(qs == 2 || qs == 3)yc -= del;
+ else yc += del;
+ dy = yc-y;
+ pc = r-dy*dy;
+ xc = m*sqrt(pc)+x;
+ if((x < xs && x >= xc) || ( x > xs && x <= xc) ||
+ (y < ys && y >= yc) || ( y > ys && y <= yc) )
+ {
+ if(++qs > 4)qs=1;
+ if(qs == 2 || qs == 3)m= -1;
+ else m=1;
+ flg=1;
+ }
+ cont(xc,yc);
+ xs = xc;
+ ys = yc;
+ if(qs == qf && flg == 1)
+ switch(qf){
+ case 3:
+ case 4:
+ if(xs >= x1)return;
+ continue;
+ case 1:
+ case 2:
+ if(xs <= x1)return;
+ }
+ continue;
+ case 'y':
+ if(qs > 2)xc += del;
+ else xc -= del;
+ dx = xc-x;
+ pc = r-dx*dx;
+ yc = m*sqrt(pc)+y;
+ if((x < xs && x >= xc) || ( x > xs && x <= xc ) ||
+ (y < ys && y >= yc) || (y > ys && y <= yc) )
+ {
+ if(++qs > 4)qs=1;
+ if(qs > 2)m = -1;
+ else m = 1;
+ flg=1;
+ }
+ cont(xc,yc);
+ xs = xc;
+ ys = yc;
+ if(qs == qf && flg == 1)
+ switch(qs){
+ case 1:
+ case 4:
+ if(ys >= y1)return;
+ continue;
+ case 2:
+ case 3:
+ if(ys <= y1)return;
+ }
+ }
+ }
+}
+quad(x,y,xp,yp){
+ if(x < xp)
+ if(y <= yp)return(1);
+ else return(4);
+ else if(x > xp)
+ if(y < yp)return(2);
+ else return(3);
+ else if(y < yp)return(2);
+ else return(4);
+}
+abs(a){
+ if(a < 0)return(-a);
+ return(a);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/box.c b/usr/src/ucbcmd/plot/libplot/t4014/box.c
new file mode 100644
index 0000000000..190476f237
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/box.c
@@ -0,0 +1,41 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/circle.c b/usr/src/ucbcmd/plot/libplot/t4014/circle.c
new file mode 100644
index 0000000000..78e902fc43
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/circle.c
@@ -0,0 +1,35 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+circle(x,y,r){
+ arc(x,y,x+r,y,x+r,y);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/close.c b/usr/src/ucbcmd/plot/libplot/t4014/close.c
new file mode 100644
index 0000000000..4ae674b853
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/close.c
@@ -0,0 +1,41 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include <stdio.h>
+closevt(){
+ putch(037);
+ fflush(stdout);
+}
+closepl(){
+ putch(037);
+ fflush(stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/dot.c b/usr/src/ucbcmd/plot/libplot/t4014/dot.c
new file mode 100644
index 0000000000..06dde59777
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/dot.c
@@ -0,0 +1,34 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/erase.c b/usr/src/ucbcmd/plot/libplot/t4014/erase.c
new file mode 100644
index 0000000000..dabf6915e6
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/erase.c
@@ -0,0 +1,47 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+extern int ohiy;
+extern int ohix;
+extern int oloy;
+extern int oextra;
+erase(){
+ int i;
+ putch(033);
+ putch(014);
+ ohiy= -1;
+ ohix = -1;
+ oextra = -1;
+ oloy = -1;
+ sleep(2);
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/label.c b/usr/src/ucbcmd/plot/libplot/t4014/label.c
new file mode 100644
index 0000000000..5534beb542
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/label.c
@@ -0,0 +1,60 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#define N 0104
+#define E 0101
+#define NE 0105
+#define S 0110
+#define W 0102
+#define SW 0112
+/* arrange by incremental plotting that an initial
+ * character such as +, X, *, etc will fall
+ * right on the point, and undo it so that further
+ * labels will fall properly in place
+ */
+char lbl_mv[] = {
+ 036,040,S,S,S,S,S,S,SW,SW,SW,SW,SW,SW,SW,SW,SW,SW,037,0
+};
+char lbl_umv[] = {
+ 036,040,N,N,N,N,N,N,NE,NE,NE,NE,NE,NE,NE,NE,NE,NE,037,0
+};
+label(s)
+char *s;
+{
+ register i,c;
+ for(i=0; c=lbl_mv[i]; i++)
+ putch(c);
+ for(i=0; c=s[i]; i++)
+ putch(c);
+ for(i=0; c=lbl_umv[i]; i++)
+ putch(c);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/line.c b/usr/src/ucbcmd/plot/libplot/t4014/line.c
new file mode 100644
index 0000000000..eed81a69b3
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/line.c
@@ -0,0 +1,36 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+line(x0,y0,x1,y1){
+ move(x0,y0);
+ cont(x1,y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/linemod.c b/usr/src/ucbcmd/plot/libplot/t4014/linemod.c
new file mode 100644
index 0000000000..c1b0fcca89
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/linemod.c
@@ -0,0 +1,51 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+linemod(s)
+char *s;
+{
+ char c;
+ putch(033);
+ switch(s[0]){
+ case 'l':
+ c = 'd';
+ break;
+ case 'd':
+ if(s[3] != 'd')c='a';
+ else c='b';
+ break;
+ case 's':
+ if(s[5] != '\0')c='c';
+ else c='`';
+ }
+ putch(c);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/move.c b/usr/src/ucbcmd/plot/libplot/t4014/move.c
new file mode 100644
index 0000000000..a9213ff592
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/move.c
@@ -0,0 +1,36 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+move(xi,yi){
+ putch(035);
+ cont(xi,yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/open.c b/usr/src/ucbcmd/plot/libplot/t4014/open.c
new file mode 100644
index 0000000000..3e8d5db7e9
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/open.c
@@ -0,0 +1,37 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+openvt ()
+{
+}
+openpl(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/point.c b/usr/src/ucbcmd/plot/libplot/t4014/point.c
new file mode 100644
index 0000000000..fd0d3df99e
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/point.c
@@ -0,0 +1,36 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+point(xi,yi){
+ move(xi,yi);
+ cont(xi,yi);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/space.c b/usr/src/ucbcmd/plot/libplot/t4014/space.c
new file mode 100644
index 0000000000..812e3e5708
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/space.c
@@ -0,0 +1,49 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+extern float botx;
+extern float boty;
+extern float obotx;
+extern float oboty;
+extern float scalex;
+extern float scaley;
+extern int scaleflag;
+space(x0,y0,x1,y1){
+ botx = 0.;
+ boty = 0.;
+ obotx = x0;
+ oboty = y0;
+ if(scaleflag)
+ return;
+ scalex = 3120./(x1-x0);
+ scaley = 3120./(y1-y0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t4014/subr.c b/usr/src/ucbcmd/plot/libplot/t4014/subr.c
new file mode 100644
index 0000000000..d5782701f4
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t4014/subr.c
@@ -0,0 +1,90 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include <stdio.h>
+float obotx = 0.;
+float oboty = 0.;
+float botx = 0.;
+float boty = 0.;
+float scalex = 1.;
+float scaley = 1.;
+int scaleflag;
+
+int oloy = -1;
+int ohiy = -1;
+int ohix = -1;
+int oextra = -1;
+cont(x,y){
+ int hix,hiy,lox,loy,extra;
+ int n;
+ x = (x-obotx)*scalex + botx;
+ y = (y-oboty)*scaley + boty;
+ hix=(x>>7) & 037;
+ hiy=(y>>7) & 037;
+ lox = (x>>2)&037;
+ loy=(y>>2)&037;
+ extra=(x & 03) | ((y & 03) << 2);
+ n = (abs(hix-ohix) + abs(hiy-ohiy) + 6) / 12;
+ if(hiy != ohiy){
+ putch(hiy|040);
+ ohiy=hiy;
+ }
+ if(hix != ohix){
+ if(extra != oextra){
+ putch(extra|0140);
+ oextra=extra;
+ }
+ putch(loy|0140);
+ putch(hix|040);
+ ohix=hix;
+ oloy=loy;
+ }
+ else{
+ if(extra != oextra){
+ putch(extra|0140);
+ putch(loy|0140);
+ oextra=extra;
+ oloy=loy;
+ }
+ else if(loy != oloy){
+ putch(loy|0140);
+ oloy=loy;
+ }
+ }
+ putch(lox|0100);
+ while(n--)
+ putch(0);
+}
+
+putch(c){
+ putc(c,stdout);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/Makefile b/usr/src/ucbcmd/plot/libplot/t450/Makefile
new file mode 100644
index 0000000000..070b869669
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/Makefile
@@ -0,0 +1,53 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY= ../libt450.a
+
+OBJECTS = arc.o box.o circle.o close.o dot.o erase.o label.o \
+ line.o linmod.o move.o open.o point.o space.o subr.o
+
+# include library definitions
+include ../../../../lib/Makefile.lib
+
+C99MODE= $(C99_DISABLE)
+
+# Specifically request the construction of a static library.
+# This library is not installed in the proto area.
+LIBS = $(LIBRARY)
+
+BUILD.AR = $(AR) $(ARFLAGS) $@ `$(LORDER) $(AROBJS) | $(TSORT)`
+
+
+CLOBBERFILES= $(LIBRARY)
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+include ../../../../lib/Makefile.targ
+
diff --git a/usr/src/ucbcmd/plot/libplot/t450/arc.c b/usr/src/ucbcmd/plot/libplot/t450/arc.c
new file mode 100644
index 0000000000..8be09951b5
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/arc.c
@@ -0,0 +1,34 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+arc(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/box.c b/usr/src/ucbcmd/plot/libplot/t450/box.c
new file mode 100644
index 0000000000..190476f237
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/box.c
@@ -0,0 +1,41 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+box(x0, y0, x1, y1)
+{
+ move(x0, y0);
+ cont(x0, y1);
+ cont(x1, y1);
+ cont(x1, y0);
+ cont(x0, y0);
+ move(x1, y1);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/circle.c b/usr/src/ucbcmd/plot/libplot/t450/circle.c
new file mode 100644
index 0000000000..d29326de64
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/circle.c
@@ -0,0 +1,34 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+circle(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/close.c b/usr/src/ucbcmd/plot/libplot/t450/close.c
new file mode 100644
index 0000000000..ef9737b830
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/close.c
@@ -0,0 +1,40 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include <stdio.h>
+closevt(){
+ closepl();
+}
+closepl(){
+ fflush(stdout);
+ reset();
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/con.h b/usr/src/ucbcmd/plot/libplot/t450/con.h
new file mode 100644
index 0000000000..72506e3942
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/con.h
@@ -0,0 +1,60 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include <sgtty.h>
+/* gsi plotting output routines */
+# define DOWN 012
+# define UP 013
+# define LEFT 010
+# define RIGHT 040
+# define BEL 007
+# define ESC 033
+# define ACK 006
+#define PLOTIN 063
+#define PLOTOUT 064
+# define CR 015
+# define FF 014
+# define VERTRESP 48
+# define HORZRESP 60.
+# define VERTRES 8.
+# define HORZRES 6.
+/* down is line feed, up is reverse line feed,
+ left is backspace, right is space. 48 points per inch
+ vertically, 60 horizontally */
+
+extern int xnow, ynow;
+extern int OUTF;
+extern struct sgttyb ITTY, PTTY;
+extern float HEIGHT, WIDTH, OFFSET;
+extern int xscale, xoffset, yscale;
+extern float botx, boty, obotx, oboty, scalex,scaley;
+
diff --git a/usr/src/ucbcmd/plot/libplot/t450/dot.c b/usr/src/ucbcmd/plot/libplot/t450/dot.c
new file mode 100644
index 0000000000..06dde59777
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/dot.c
@@ -0,0 +1,34 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+dot(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/erase.c b/usr/src/ucbcmd/plot/libplot/t450/erase.c
new file mode 100644
index 0000000000..969a1d5f63
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/erase.c
@@ -0,0 +1,39 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include "con.h"
+erase(){
+ int i;
+ for(i=0; i<11*(VERTRESP/VERTRES); i++)
+ spew(DOWN);
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/label.c b/usr/src/ucbcmd/plot/libplot/t450/label.c
new file mode 100644
index 0000000000..0cc08977cc
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/label.c
@@ -0,0 +1,43 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include "con.h"
+label(s)
+char *s;
+{
+ int i,c;
+ while((c = *s++) != '\0'){
+ xnow += 6;
+ spew(c);
+ }
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/line.c b/usr/src/ucbcmd/plot/libplot/t450/line.c
new file mode 100644
index 0000000000..226fee3148
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/line.c
@@ -0,0 +1,77 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include "con.h"
+line(x0,y0,x1,y1){
+ iline(xconv(xsc(x0)),yconv(ysc(y0)),xconv(xsc(x1)),yconv(ysc(y1)));
+ return;
+}
+cont(x0,y0){
+ iline(xnow,ynow,xconv(xsc(x0)),yconv(ysc(y0)));
+ return;
+}
+iline(cx0,cy0,cx1,cy1){
+ int maxp,tt,j,np;
+ char chx,chy;
+ float xd,yd;
+ float dist2(),sqrt();
+ movep(cx0,cy0);
+ maxp = sqrt(dist2(cx0,cy0,cx1,cy1))/2.;
+ xd = cx1-cx0;
+ yd = cy1-cy0;
+ if(xd >= 0)chx = RIGHT;
+ else chx = LEFT;
+ if(yd >= 0)chy = UP;
+ else chy = DOWN;
+ if(maxp == 0){
+ xd=0;
+ yd=0;
+ }
+ else{
+ xd /= maxp;
+ yd /= maxp;
+ }
+ inplot();
+ for (tt=0; tt<=maxp; tt++){
+ j= cx0+xd*tt-xnow;
+ xnow += j;
+ j = abval(j);
+ while(j-- > 0)spew(chx);
+ j = cy0+yd*tt-ynow;
+ ynow += j;
+ j = abval(j);
+ while(j-- > 0)spew(chy);
+ spew ('.');
+ }
+ outplot();
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/linmod.c b/usr/src/ucbcmd/plot/libplot/t450/linmod.c
new file mode 100644
index 0000000000..b1731bdbe9
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/linmod.c
@@ -0,0 +1,34 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+linemod(){
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/move.c b/usr/src/ucbcmd/plot/libplot/t450/move.c
new file mode 100644
index 0000000000..a0b158bf8d
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/move.c
@@ -0,0 +1,36 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+move(xi,yi){
+ movep(xconv(xsc(xi)),yconv(ysc(yi)));
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/open.c b/usr/src/ucbcmd/plot/libplot/t450/open.c
new file mode 100644
index 0000000000..6171d87d47
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/open.c
@@ -0,0 +1,82 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#
+#include <sgtty.h>
+/* gsi plotting output routines */
+# define DOWN 012
+# define UP 013
+# define LEFT 010
+# define RIGHT 040
+# define BEL 007
+# define ACK 006
+#define PLOTIN 063
+#define PLOTOUT 064
+# define CR 015
+# define FF 014
+# define VERTRESP 48
+# define HORZRESP 60.
+# define HORZRES 6.
+# define VERTRES 8.
+/* down is line feed, up is reverse oyne feed,
+ left is bwckspace, right is space. 48 points per inch
+ vertically, 60 horizontally */
+
+int xnow, ynow;
+int OUTF;
+struct sgttyb ITTY, PTTY;
+float HEIGHT = 6.0, WIDTH = 6.0, OFFSET = 0.0;
+int xscale, xoffset, yscale;
+float botx = 0., boty = 0., obotx = 0., oboty = 0.;
+float scalex = 1., scaley = 1.;
+
+openpl ()
+{
+ int reset();
+ xnow = ynow = 0;
+ OUTF = 1;
+ printf("\r");
+ gtty(OUTF, &ITTY);
+ signal (2, reset);
+ PTTY = ITTY;
+ PTTY.sg_flags &= ~CRMOD; /* don't map lf */
+ stty(OUTF,&PTTY);
+ /* initialize constants */
+ xscale = 4096./(HORZRESP * WIDTH);
+ yscale = 4096 /(VERTRESP * HEIGHT);
+ xoffset = OFFSET * HORZRESP;
+ return;
+}
+
+openvt(){
+openpl();
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/point.c b/usr/src/ucbcmd/plot/libplot/t450/point.c
new file mode 100644
index 0000000000..7389adde38
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/point.c
@@ -0,0 +1,37 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+point(xi,yi){
+ move(xi,yi);
+ label(".");
+ return;
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/space.c b/usr/src/ucbcmd/plot/libplot/t450/space.c
new file mode 100644
index 0000000000..70f60955d4
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/space.c
@@ -0,0 +1,41 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+# include "con.h"
+space(x0,y0,x1,y1){
+ botx = -2047.;
+ boty = -2047.;
+ obotx = x0;
+ oboty = y0;
+ scalex = 4096./(x1-x0);
+ scaley = 4096./(y1-y0);
+}
diff --git a/usr/src/ucbcmd/plot/libplot/t450/subr.c b/usr/src/ucbcmd/plot/libplot/t450/subr.c
new file mode 100644
index 0000000000..05fb7841a7
--- /dev/null
+++ b/usr/src/ucbcmd/plot/libplot/t450/subr.c
@@ -0,0 +1,148 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#include <stdio.h>
+#include "con.h"
+abval(q)
+{
+ return (q>=0 ? q : -q);
+}
+
+xconv (xp)
+{
+ /* x position input is -2047 to +2047, output must be 0 to PAGSIZ*HORZRES */
+ xp += 2048;
+ /* the computation is newx = xp*(PAGSIZ*HORZRES)/4096 */
+ return (xoffset + xp /xscale);
+}
+
+yconv (yp)
+{
+ /* see description of xconv */
+ yp += 2048;
+ return (yp / yscale);
+}
+
+inplot()
+{
+ spew (ESC);
+ spew(PLOTIN);
+}
+
+outplot()
+{
+ spew(ESC);
+ spew(PLOTOUT);
+ fflush(stdout);
+}
+
+spew(ch)
+{
+ if(ch == UP){
+ putc(ESC,stdout);
+ ch = DOWN;
+ }
+ putc(ch, stdout);
+}
+
+tobotleft ()
+{
+ move(-2048,-2048);
+}
+reset()
+{
+ signal(2,1);
+ outplot();
+ stty(OUTF,&ITTY);
+ exit(0);
+}
+
+float
+dist2 (x1, y1, x2, y2)
+{
+ float t,v;
+ t = x2-x1;
+ v = y1-y2;
+ return (t*t+v*v);
+}
+
+swap (pa, pb)
+int *pa, *pb;
+{
+ int t;
+ t = *pa;
+ *pa = *pb;
+ *pb = t;
+}
+movep (xg,yg)
+{
+ int i,ch;
+ if((xg == xnow) && (yg == ynow))return;
+ /* if we need to go to left margin, just CR */
+ if (xg < xnow/2)
+ {
+ spew(CR);
+ xnow = 0;
+ }
+ i = (xg-xnow)/HORZRES;
+ if(xnow < xg)ch = RIGHT;
+ else ch = LEFT;
+ xnow += i*HORZRES;
+ i = abval(i);
+ while(i--)spew(ch);
+ i = abval(xg-xnow);
+ inplot();
+ while(i--) spew(ch);
+ outplot();
+ i=(yg-ynow)/VERTRES;
+ if(ynow < yg)ch = UP;
+ else ch = DOWN;
+ ynow += i*VERTRES;
+ i = abval(i);
+ while(i--)spew(ch);
+ i=abval(yg-ynow);
+ inplot();
+ while(i--)spew(ch);
+ outplot();
+ xnow = xg; ynow = yg;
+}
+
+xsc(xi){
+ int xa;
+ xa = (xi - obotx) * scalex + botx;
+ return(xa);
+}
+ysc(yi){
+ int ya;
+ ya = (yi - oboty) *scaley +boty;
+ return(ya);
+}
diff --git a/usr/src/ucbcmd/plot/plot.sh b/usr/src/ucbcmd/plot/plot.sh
new file mode 100644
index 0000000000..4600eaa838
--- /dev/null
+++ b/usr/src/ucbcmd/plot/plot.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/sh
+
+# Copyright 1988 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+
+# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+# All Rights Reserved
+
+# University Copyright- Copyright (c) 1982, 1986, 1988
+# The Regents of the University of California
+# All Rights Reserved
+#
+# University Acknowledgment- Portions of this document are derived from
+# software developed by the University of California, Berkeley, and its
+# contributors.
+
+#ident "%Z%%M% %I% %E% SMI"
+
+
+PATH=/bin:/usr/bin:/usr/ucb
+case $1 in
+-T*) t=$1
+ shift ;;
+*) t=-T$TERM
+esac
+case $t in
+-T450) exec t450 $*;;
+-T300) exec t300 $*;;
+-T300S|-T300s) exec t300s $*;;
+-Tver) exec lpr -Pversatec -g $*;;
+-Tvar) exec lpr -Pvarian -g $*;;
+-Ttek|-T4014|-T) exec tek $* ;;
+-T4013) exec t4013 $* ;;
+-Tbitgraph|-Tbg) exec bgplot $*;;
+-Tgigi|-Tvt125) exec gigiplot $*;;
+-Taed) exec aedplot $*;;
+-Thp7221|-Thp7|-Th7) exec hp7221plot $*;;
+-Thp|-T2648|-T2648a|-Thp2648|-Thp2648a|h8)
+ exec hpplot $*;;
+-Tip|-Timagen) exec implot $*;;
+-Tdumb|un|unknown) exec dumbplot $*;;
+*) exec crtplot $*;;
+esac
diff --git a/usr/src/ucbcmd/plot/plottoa.c b/usr/src/ucbcmd/plot/plottoa.c
new file mode 100644
index 0000000000..9f74001372
--- /dev/null
+++ b/usr/src/ucbcmd/plot/plottoa.c
@@ -0,0 +1,240 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+ * Convert the standard plot input into a readable form for debugging.
+ */
+
+#include <stdio.h>
+
+float deltx;
+float delty;
+
+main(argc, argv)
+char **argv;
+{
+ int std=1;
+ FILE *fin;
+
+ while(argc-- > 1) {
+ if(*argv[1] == '-')
+ switch(argv[1][1]) {
+ case 'l':
+ deltx = atoi(&argv[1][2]) - 1;
+ break;
+ case 'w':
+ delty = atoi(&argv[1][2]) - 1;
+ break;
+ }
+ else {
+ std = 0;
+ if ((fin = fopen(argv[1], "r")) == NULL) {
+ fprintf(stderr, "can't open %s\n", argv[1]);
+ exit(1);
+ }
+ fplt(fin);
+ fclose(fin);
+ }
+ argv++;
+ }
+ if (std)
+ fplt( stdin );
+ exit(0);
+}
+
+
+fplt(fin)
+FILE *fin;
+{
+ int c;
+ char s[256];
+ int xi,yi,x0,y0,x1,y1,r,dx,n,i;
+ int pat[256];
+
+ openpl();
+ while((c = getc(fin)) != EOF){
+ switch(c){
+ case 'm':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ move(xi,yi);
+ break;
+ case 'l':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ line(x0,y0,x1,y1);
+ break;
+ case 't':
+ getstr(s,fin);
+ label(s);
+ break;
+ case 'e':
+ erase();
+ break;
+ case 'p':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ point(xi,yi);
+ break;
+ case 'n':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ cont(xi,yi);
+ break;
+ case 's':
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ space(x0,y0,x1,y1);
+ break;
+ case 'a':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ x0 = getsi(fin);
+ y0 = getsi(fin);
+ x1 = getsi(fin);
+ y1 = getsi(fin);
+ arc(xi,yi,x0,y0,x1,y1);
+ break;
+ case 'c':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ r = getsi(fin);
+ circle(xi,yi,r);
+ break;
+ case 'f':
+ getstr(s,fin);
+ linemod(s);
+ break;
+ case 'd':
+ xi = getsi(fin);
+ yi = getsi(fin);
+ dx = getsi(fin);
+ n = getsi(fin);
+ for(i=0; i<n; i++)pat[i] = getsi(fin);
+ dot(xi,yi,dx,n,pat);
+ break;
+ }
+ }
+ closepl();
+}
+
+/* get an integer stored in 2 ascii bytes. */
+getsi(fin)
+FILE *fin;
+{
+ short a, b;
+ if((b = getc(fin)) == EOF)
+ return(EOF);
+ if((a = getc(fin)) == EOF)
+ return(EOF);
+ a = a<<8;
+ return(a|b);
+}
+
+getstr(s,fin)
+char *s;
+FILE *fin;
+{
+ for( ; *s = getc(fin); s++)
+ if(*s == '\n')
+ break;
+ *s = '\0';
+}
+
+/* Print out the arguments to plot routines. */
+
+space(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ printf( "s %d %d %d %d\n", x0, y0, x1, y1 );
+}
+
+openpl()
+{
+}
+
+closepl()
+{
+}
+
+erase()
+{
+ printf( "e\n" );
+}
+
+move(xi,yi)
+int xi,yi;
+{
+ printf( "m %d %d\n", xi, yi );
+}
+
+cont(xi,yi)
+int xi,yi;
+{
+ printf( "n %d %d\n", xi, yi );
+}
+
+line(x0,y0,x1,y1)
+int x0,y0,x1,y1;
+{
+ printf( "l %d %d %d %d\n", x0, y0, x1, y1 );
+}
+
+point(xi,yi)
+int xi,yi;
+{
+ printf( "p %d %d\n", xi, yi );
+}
+
+label(s)
+char *s;
+{
+ printf( "t%s\n\n", s );
+}
+
+
+arc(xcent,ycent,xbeg,ybeg,xend,yend)
+int xcent,ycent,xbeg,ybeg,xend,yend;
+{
+ printf( "a %d %d %d %d %d %d\n", xcent, ycent, xbeg, ybeg, xend, yend );
+}
+
+circle (xc,yc,r)
+int xc,yc,r;
+{
+ printf( "c %d %d %d\n", xc, yc, r );
+}
+
+linemod( line )
+char *line;
+{
+ printf( "f%s\n\n", line );
+}
+
+/* don't know what this should do */
+dot(xi,yi,dx,n,pat)
+int xi,yi,dx,n;
+char *pat;
+{
+ printf("d %d %d %d %d %s\n\n", xi, yi, dx, n, pat);
+}
diff --git a/usr/src/ucbcmd/plot/vfont.h b/usr/src/ucbcmd/plot/vfont.h
new file mode 100644
index 0000000000..e259380f98
--- /dev/null
+++ b/usr/src/ucbcmd/plot/vfont.h
@@ -0,0 +1,48 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+ * The structures header and dispatch define the format of a font file.
+ *
+ * A font file contains one struct 'header', an array of NUM_DISPATCH struct
+ * 'dispatch'es, then an array of bytes containing bit maps.
+ *
+ * See vfont(5) for more details.
+ */
+
+#ifndef _vfont_h
+#define _vfont_h
+
+struct header {
+ short magic; /* Magic number VFONT_MAGIC */
+ unsigned short size; /* Total # bytes of bitmaps */
+ short maxx; /* Maximum horizontal glyph size */
+ short maxy; /* Maximum vertical glyph size */
+ short xtend; /* (unused?) */
+};
+#define VFONT_MAGIC 0436
+
+struct dispatch {
+ unsigned short addr; /* &(glyph) - &(start of bitmaps) */
+ short nbytes; /* # bytes of glyphs (0 if no glyph) */
+ char up, down, left, right; /* Widths from baseline point */
+ short width; /* Logical width, used by troff */
+};
+#define NUM_DISPATCH 256
+
+#endif /*!_vfont_h*/
diff --git a/usr/src/ucbcmd/plot/vplot.c b/usr/src/ucbcmd/plot/vplot.c
new file mode 100644
index 0000000000..0bf0935595
--- /dev/null
+++ b/usr/src/ucbcmd/plot/vplot.c
@@ -0,0 +1,510 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+
+/*
+ * Reads standard graphics input and produces a plot on the
+ * Varian or Versatec
+ */
+#include <stdio.h>
+#include <sys/types.h>
+#include <signal.h>
+#include "vfont.h"
+
+#define LPR "/usr/ucb/lpr"
+
+#define mapx(x) ((DevRange*((x)-botx)/del)+centx)
+#define mapy(y) ((DevRange*(del-(y)+boty)/del)-centy)
+#define SOLID -1
+#define DOTTED 014
+#define SHORTDASHED 034
+#define DOTDASHED 054
+#define LONGDASHED 074
+
+int linmod = SOLID;
+int done1;
+extern char chrtab[][16];
+char *obuf;
+int bufsize;
+int lastx;
+int lasty;
+int radius, startx, starty, endx, endy;
+double topx;
+double topy;
+double botx;
+double boty;
+int centx = 0;
+int centy = 0;
+double delx;
+double dely;
+double del;
+
+int warned = 0; /* Indicates whether the warning message about
+ * unimplemented routines has been printed */
+
+FILE *infile;
+FILE *pfp; /* output file */
+char picture[] = "/usr/tmp/rastAXXXXXX";
+int run = 13; /* index of 'a' in picture[] */
+int DevRange = 1536; /* output array size (square) in pixels */
+int DevRange8 = 1536/8; /* output array size in bytes */
+int BytesPerLine = 264; /* Bytes per raster line (physical) */
+int lparg = 7; /* index into lpargs */
+
+#ifdef sun
+char *lpargs[50] = { "lpr", "-Pversatec", "-v", "-s", "-r", "-J", "vplot" };
+#else
+char *lpargs[50] = { "lpr", "-Pvarian", "-v", "-s", "-r", "-J", "vplot" };
+#endif
+
+/* variables for used to print from font file */
+void cleanup();
+int fontSet = 0; /* Has the font file been read */
+struct header header;
+struct dispatch dispatch[256];
+char *bits;
+char *fontFile = "/usr/lib/vfont/R.6";
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+ register char *cp1, *arg;
+ register i;
+ int again;
+
+ infile = stdin;
+ while (argc > 1 && argv[1][0] == '-') {
+ argc--;
+ arg = *++argv;
+ switch (*++arg) {
+ case 'W':
+ DevRange = 2048;
+ DevRange8 = 2048/8;
+ BytesPerLine = 880;
+#ifdef sun
+ lpargs[1] = "-PWversatec";
+#else
+ lpargs[1] = "-Pversatec";
+#endif
+ break;
+ case 'V':
+ DevRange = 1536;
+ DevRange8 = 1536/8;
+ BytesPerLine = 264;
+#ifdef sun
+ lpargs[1] = "-Pversatec";
+#else
+ lpargs[1] = "-Pvarian";
+#endif
+ break;
+ case 'b':
+ if (argc-- > 1)
+ lpargs[lparg-1] = *++argv;
+ break;
+ default:
+ fprintf(stderr, "vplot: %s option unknown\n", *argv);
+ break;
+ }
+ }
+ if (argc > 1) {
+ if ((infile = fopen(*++argv, "r")) == NULL) {
+ perror(*argv);
+ cleanup();
+ }
+ }
+
+ /* init constants for scaling */
+ topx = topy = DevRange;
+ botx = boty = 0;
+ delx = dely = del = DevRange;
+ centx = (DevRange - mapx(topx))/2;
+ centy = mapy(topy)/2;
+ signal(SIGTERM, cleanup);
+ if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+ signal(SIGINT, cleanup);
+ mktemp(picture);
+ if ((obuf = (char *) malloc(bufsize = DevRange * DevRange8)) == NULL) {
+ fprintf(stderr, "vplot: ran out of memory\n");
+ cleanup();
+ }
+ do {
+ if ((pfp = fopen(picture, "w")) == NULL) {
+ fprintf(stderr, "vplot: can't create %s\n", picture);
+ cleanup();
+ }
+ i = strlen(picture) + 1;
+ if ((arg = (char *) malloc(i)) == NULL) {
+ fprintf(stderr, "ran out of memory\n");
+ cleanup();
+ }
+ strcpy(arg, picture);
+ lpargs[lparg++] = arg;
+ picture[run]++;
+ arg = &obuf[bufsize];
+ for (cp1 = obuf; cp1 < arg; )
+ *cp1++ = 0;
+
+ again = getpict();
+
+ for (cp1 = obuf; cp1 < arg; cp1 += DevRange8) {
+ fwrite(cp1, sizeof(char), DevRange8, pfp);
+ fseek(pfp, (long) BytesPerLine - DevRange8, 1);
+ }
+ fclose(pfp);
+ } while (again);
+ lpargs[lparg] = 0;
+ execv(LPR, lpargs);
+ fprintf(stderr, "can't exec %s\n", LPR);
+ cleanup();
+}
+
+getpict()
+{
+ register x1, y1;
+
+ for (;;) switch (x1 = getc(infile)) {
+
+ case '\n':
+ continue;
+
+ case 's':
+ botx = getinteger(infile);
+ boty = getinteger(infile);
+ topx = getinteger(infile);
+ topy = getinteger(infile);
+ delx = topx-botx;
+ dely = topy-boty;
+ if (dely/delx > 1536./2048.)
+ del = dely;
+ else
+ del = delx;
+ centx = 0;
+ centx = (DevRange - mapx(topx))/2;
+ centy = 0;
+ centy = mapy(topy) / 2;
+ continue;
+
+ case 'b':
+ x1 = getc(infile);
+ continue;
+
+ case 'l':
+ done1 |= 01;
+ x1 = mapx(getinteger(infile));
+ y1 = mapy(getinteger(infile));
+ lastx = mapx(getinteger(infile));
+ lasty = mapy(getinteger(infile));
+ line(x1, y1, lastx, lasty);
+ continue;
+
+ case 'c':
+ x1 = mapx(getinteger(infile));
+ y1 = mapy(getinteger(infile));
+ radius = mapx(getinteger(infile));
+ if (!warned) {
+ fprintf(stderr,"Circles are Implemented\n");
+ warned++;
+ }
+ circle(x1, y1, radius);
+ continue;
+
+ case 'a':
+ x1 = mapx(getinteger(infile));
+ y1 = mapy(getinteger(infile));
+ startx = mapx(getinteger(infile));
+ starty = mapy(getinteger(infile));
+ endx = mapx(getinteger(infile));
+ endy = mapy(getinteger(infile));
+ if (!warned) {
+ fprintf(stderr,"Circles and Arcs are unimplemented\n");
+ warned++;
+ }
+ continue;
+
+ case 'm':
+ lastx = mapx(getinteger(infile));
+ lasty = mapy(getinteger(infile));
+ continue;
+
+ case 't':
+ lastx = lastx - 6;
+ lasty = lasty + 6;
+ done1 |= 01;
+ while ((x1 = getc(infile)) != '\n')
+ plotch(x1);
+ continue;
+
+ case 'e':
+ if (done1)
+ return(1);
+ continue;
+
+ case 'p':
+ done1 |= 01;
+ lastx = mapx(getinteger(infile));
+ lasty = mapy(getinteger(infile));
+ point(lastx, lasty);
+ point(lastx+1, lasty);
+ point(lastx, lasty+1);
+ point(lastx+1, lasty+1);
+ continue;
+
+ case 'n':
+ done1 |= 01;
+ x1 = mapx(getinteger(infile));
+ y1 = mapy(getinteger(infile));
+ line(lastx, lasty, x1, y1);
+ lastx = x1;
+ lasty = y1;
+ continue;
+
+ case 'f':
+ getinteger(infile);
+ getc(infile);
+ switch (getc(infile)) {
+ case 't':
+ linmod = DOTTED;
+ break;
+ default:
+ case 'i':
+ linmod = SOLID;
+ break;
+ case 'g':
+ linmod = LONGDASHED;
+ break;
+ case 'r':
+ linmod = SHORTDASHED;
+ break;
+ case 'd':
+ linmod = DOTDASHED;
+ break;
+ }
+ while ((x1 = getc(infile)) != '\n')
+ if (x1 == EOF)
+ return(0);
+ continue;
+
+ case 'd':
+ getinteger(infile);
+ getinteger(infile);
+ getinteger(infile);
+ x1 = getinteger(infile);
+ while (--x1 >= 0)
+ getinteger(infile);
+ continue;
+
+ case 0: /* ignore null characters */
+ continue;
+
+ case 255:
+ case EOF:
+ return(0);
+
+ default:
+ fprintf(stderr, "Input format error %c(%o)\n",x1,x1);
+ cleanup();
+ }
+}
+
+plotch(ch)
+char ch;
+{
+ register int i,j,k;
+ register char *ptr,c;
+ int nbytes;
+
+ if (!fontSet)
+ InitFont(); /* Read font if not already read */
+
+ ptr = bits + dispatch[ch].addr;
+
+ for (i = dispatch[ch].up; i > -dispatch[ch].down; --i) {
+ nbytes = (dispatch[ch].right + dispatch[ch].left + 7)/8;
+ for (j = 0; j < nbytes; j++) {
+ c = *ptr++;
+ for (k = 7; k >= 0; k--)
+ if ((c >> k) & 1)
+ point(lastx+7-k+j*8-dispatch[ch].left, lasty-i);
+ }
+ }
+ if (ch != ' ')
+ lastx += dispatch[ch].width;
+ else
+ lastx += dispatch['a'].width;
+}
+
+InitFont()
+{
+ char *s;
+ int fonts;
+ int i;
+
+ fontSet = 1;
+ /* Get the font file */
+ s = fontFile;
+ if ((fonts = open(s, 0)) == -1) {
+ perror(s);
+ fprintf(stderr, "Can't get font file");
+ cleanup();
+ }
+ /* Get the header and check magic number */
+ if (read(fonts, &header, sizeof(header)) != sizeof(header)) {
+ perror(s);
+ fprintf(stderr, "Bad read in font file");
+ cleanup();
+ }
+ if (header.magic != 0436) {
+ fprintf(stderr,"Bad magic numer in font file");
+ cleanup();
+ }
+ /* Get dispatches */
+ if (read(fonts, dispatch, sizeof(dispatch)) != sizeof(dispatch)) {
+ perror(s);
+ fprintf(stderr, "Bad read in font file");
+ cleanup();
+ }
+ /* Allocate space for bit map and read in bits */
+ bits = (char *) malloc(header.size);
+ if (read(fonts, bits, header.size) != header.size) {
+ perror(s);
+ fprintf(stderr,"Can't read bit map in font file");
+ cleanup();
+ }
+ /* Close font file */
+ if (close(fonts) != 0) {
+ perror(s);
+ fprintf(stderr,"Can't close font file");
+ cleanup();
+ }
+}
+
+line(x0, y0, x1, y1)
+register x0, y0;
+{
+ int dx, dy;
+ int xinc, yinc;
+ register res1;
+ int res2;
+ int slope;
+
+ xinc = 1;
+ yinc = 1;
+ if ((dx = x1-x0) < 0) {
+ xinc = -1;
+ dx = -dx;
+ }
+ if ((dy = y1-y0) < 0) {
+ yinc = -1;
+ dy = -dy;
+ }
+ slope = xinc*yinc;
+ res1 = 0;
+ res2 = 0;
+ if (dx >= dy) while (x0 != x1) {
+ if ((x0+slope*y0) & linmod)
+ point(x0, y0);
+ if (res1 > res2) {
+ res2 += dx - res1;
+ res1 = 0;
+ y0 += yinc;
+ }
+ res1 += dy;
+ x0 += xinc;
+ } else while (y0 != y1) {
+ if ((x0+slope*y0) & linmod)
+ point(x0, y0);
+ if (res1 > res2) {
+ res2 += dy - res1;
+ res1 = 0;
+ x0 += xinc;
+ }
+ res1 += dx;
+ y0 += yinc;
+ }
+ if ((x1+slope*y1) & linmod)
+ point(x1, y1);
+}
+
+#define labs(a) (a >= 0 ? a : -a)
+
+circle(x,y,c)
+{
+ register dx, dy;
+ long ep;
+ int de;
+
+ dx = 0;
+ ep = 0;
+ for (dy=c; dy>=dx; dy--) {
+ for (;;) {
+ point(x+dx, y+dy);
+ point(x-dx, y+dy);
+ point(x+dx, y-dy);
+ point(x-dx, y-dy);
+ point(x+dy, y+dx);
+ point(x-dy, y+dx);
+ point(x+dy, y-dx);
+ point(x-dy, y-dx);
+ ep += 2*dx + 1;
+ de = -2*dy + 1;
+ dx++;
+ if (labs(ep) >= labs(ep+de)) {
+ ep += de;
+ break;
+ }
+ }
+ }
+}
+
+/*
+ * Points should be in the range 0 <= x (or y) <= DevRange.
+ * The origin is the top left-hand corner with increasing x towards the
+ * right and increasing y going down.
+ */
+point(x, y)
+register int x, y;
+{
+ register unsigned byte;
+
+ byte = y * DevRange8 + (x >> 3);
+ if (byte < bufsize)
+ obuf[byte] |= 1 << (7 - (x & 07));
+}
+void
+cleanup()
+{
+ while (picture[run] != 'a') {
+ unlink(picture);
+ picture[run]--;
+ }
+ exit(1);
+}
+
+getinteger(f)
+FILE *f;
+{
+ register int low, high, result;
+
+ low = getc(f);
+ high = getc(f);
+ result = ((high << 8) | low);
+ if (high > 127)
+ result |= ~0xffff;
+ return(result);
+}
diff --git a/usr/src/ucbcmd/printenv/Makefile b/usr/src/ucbcmd/printenv/Makefile
new file mode 100644
index 0000000000..4fa3e209de
--- /dev/null
+++ b/usr/src/ucbcmd/printenv/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= printenv
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/printenv/printenv.c b/usr/src/ucbcmd/printenv/printenv.c
new file mode 100644
index 0000000000..bb1b37e636
--- /dev/null
+++ b/usr/src/ucbcmd/printenv/printenv.c
@@ -0,0 +1,83 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * printenv
+*/
+
+extern char **environ;
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ register char **ep;
+ int found = 0;
+
+ argc--, argv++;
+ if (environ)
+ for (ep = environ; *ep; ep++)
+ if (argc == 0 || prefix(argv[0], *ep)) {
+ register char *cp = *ep;
+
+ found++;
+ if (argc) {
+ while (*cp && *cp != '=')
+ cp++;
+ if (*cp == '=')
+ cp++;
+ }
+ (void)printf("%s\n", cp);
+ }
+ exit (!found);
+ /* NOTREACHED */
+}
+
+prefix(cp, dp)
+ char *cp, *dp;
+{
+
+ while (*cp && *dp && *cp == *dp)
+ cp++, dp++;
+ if (*cp == 0)
+ return (*dp == '=');
+ return (0);
+}
diff --git a/usr/src/ucbcmd/ps/Makefile b/usr/src/ucbcmd/ps/Makefile
new file mode 100644
index 0000000000..ed11e38c31
--- /dev/null
+++ b/usr/src/ucbcmd/ps/Makefile
@@ -0,0 +1,59 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989-1998 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# ucbcmd/ps/Makefile
+#
+
+PROG= ps
+
+include ../Makefile.ucbcmd
+
+SUBDIRS= $(MACH)
+$(BUILD64)SUBDIRS += $(MACH64)
+
+all := TARGET = all
+install := TARGET = install
+clean := TARGET = clean
+clobber := TARGET = clobber
+lint := TARGET = lint
+
+.KEEP_STATE:
+
+all: $(SUBDIRS)
+
+clean clobber lint: $(SUBDIRS)
+
+install: $(SUBDIRS)
+ -$(RM) $(ROOTPROG)
+ -$(LN) $(ISAEXEC) $(ROOTPROG)
+
+$(SUBDIRS): FRC
+ @cd $@; pwd; $(MAKE) $(TARGET)
+
+FRC:
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/ps/amd64/Makefile b/usr/src/ucbcmd/ps/amd64/Makefile
new file mode 100644
index 0000000000..f5836825b8
--- /dev/null
+++ b/usr/src/ucbcmd/ps/amd64/Makefile
@@ -0,0 +1,63 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+PROG= ps
+
+OBJS= ps.o
+
+SRCS= $(OBJS:%.o=../%.c)
+
+include ../../Makefile.ucbcmd
+include ../../Makefile.ucbcmd.64
+
+CFLAGS64 += $(CCVERBOSE)
+
+FILEMODE= 0555
+OWNER= root
+GROUP= sys
+
+.KEEP_STATE:
+
+%.o: ../%.c
+ $(COMPILE.c) $<
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG64)
+
+clean:
+ $(RM) $(OBJS)
+
+lint:
+ $(LINT.c) $(SRCS) $(LDLIBS)
+
+include ../../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/ps/i386/Makefile b/usr/src/ucbcmd/ps/i386/Makefile
new file mode 100644
index 0000000000..2cb47ec7a7
--- /dev/null
+++ b/usr/src/ucbcmd/ps/i386/Makefile
@@ -0,0 +1,66 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ucbcmd/ps/i386/Makefile
+#
+
+PROG= ps
+
+OBJS= ps.o
+
+SRCS= $(OBJS:%.o=../%.c)
+
+include ../../Makefile.ucbcmd
+
+CFLAGS += $(CCVERBOSE)
+
+lint := LINTFLAGS = -x
+
+FILEMODE= 0555
+OWNER= root
+GROUP= sys
+
+.KEEP_STATE:
+
+%.o: ../%.c
+ $(COMPILE.c) $<
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG32)
+
+clean:
+ $(RM) $(OBJS)
+
+lint:
+ $(LINT.c) $(SRCS) $(LDLIBS)
+
+include ../../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/ps/ps.c b/usr/src/ucbcmd/ps/ps.c
new file mode 100644
index 0000000000..598a4edea4
--- /dev/null
+++ b/usr/src/ucbcmd/ps/ps.c
@@ -0,0 +1,1189 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * ps -- print things about processes.
+ */
+
+#define _SYSCALL32
+
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mkdev.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <dirent.h>
+#include <procfs.h>
+#include <sys/param.h>
+#include <sys/ttold.h>
+#include <libelf.h>
+#include <gelf.h>
+#include <locale.h>
+#include <wctype.h>
+#include <stdarg.h>
+#include <sys/proc.h>
+#include <priv_utils.h>
+
+#define NTTYS 2 /* max ttys that can be specified with the -t option */
+ /* only one tty can be specified with SunOS ps */
+#define SIZ 30 /* max processes that can be specified with -p and -g */
+#define ARGSIZ 30 /* size of buffer holding args for -t, -p, -u options */
+
+#define FSTYPE_MAX 8
+
+struct psent {
+ psinfo_t *psinfo;
+ char *psargs;
+ int found;
+};
+
+static int tplen, maxlen, twidth;
+static char hdr[81];
+static struct winsize win;
+
+static int retcode = 1;
+static int lflg; /* long format */
+static int uflg; /* user-oriented output */
+static int aflg; /* Display all processes */
+static int eflg; /* Display environment as well as arguments */
+static int gflg; /* Display process group leaders */
+static int tflg; /* Processes running on specific terminals */
+static int rflg; /* Running processes only flag */
+static int Sflg; /* Accumulated time plus all reaped children */
+static int xflg; /* Include processes with no controlling tty */
+static int cflg; /* Display command name */
+static int vflg; /* Virtual memory-oriented output */
+static int nflg; /* Numerical output */
+static int pflg; /* Specific process id passed as argument */
+static int Uflg; /* Update private database, ups_data */
+static int errflg;
+
+static char *gettty();
+static char argbuf[ARGSIZ];
+static char *parg;
+static char *p1; /* points to successive option arguments */
+static uid_t my_uid;
+static char stdbuf[BUFSIZ];
+
+static int ndev; /* number of devices */
+static int maxdev; /* number of devl structures allocated */
+
+#define DNINCR 100
+#define DNSIZE 14
+static struct devl { /* device list */
+ char dname[DNSIZE]; /* device name */
+ dev_t ddev; /* device number */
+} *devl;
+
+static struct tty {
+ char *tname;
+ dev_t tdev;
+} tty[NTTYS]; /* for t option */
+static int ntty = 0;
+static pid_t pidsave;
+static int pidwidth;
+
+static char *procdir = "/proc"; /* standard /proc directory */
+static void usage(); /* print usage message and quit */
+static void getarg(void);
+static void prtime(timestruc_t st);
+static void przom(psinfo_t *psinfo);
+static int num(char *);
+static int preadargs(int, psinfo_t *, char *);
+static int preadenvs(int, psinfo_t *, char *);
+static int prcom(int, psinfo_t *, char *);
+static int namencnt(char *, int, int);
+static int pscompare(const void *, const void *);
+static char *err_string(int);
+
+extern int scrwidth(wchar_t); /* header file? */
+
+int
+main(int argc, char **argv)
+{
+ psinfo_t info; /* process information structure from /proc */
+ char *psargs = NULL; /* pointer to buffer for -w and -ww options */
+ char *svpsargs = NULL;
+ struct psent *psent;
+ int entsize;
+ int nent;
+ pid_t maxpid;
+
+ struct tty *ttyp = tty;
+ char *tmp;
+ char *p;
+ int c;
+ pid_t pid; /* pid: process id */
+ pid_t ppid; /* ppid: parent process id */
+ int i, found;
+
+ size_t size;
+
+ DIR *dirp;
+ struct dirent *dentp;
+ char psname[100];
+ char asname[100];
+ int pdlen;
+ size_t len;
+
+ (void) setlocale(LC_ALL, "");
+
+ my_uid = getuid();
+
+ /*
+ * This program needs the proc_owner privilege
+ */
+ (void) __init_suid_priv(PU_CLEARLIMITSET, PRIV_PROC_OWNER,
+ (char *)NULL);
+
+ /*
+ * calculate width of pid fields based on configured MAXPID
+ * (must be at least 5 to retain output format compatibility)
+ */
+ maxpid = (pid_t)sysconf(_SC_MAXPID);
+ pidwidth = 1;
+ while ((maxpid /= 10) > 0)
+ ++pidwidth;
+ pidwidth = pidwidth < 5 ? 5 : pidwidth;
+
+ if (ioctl(1, TIOCGWINSZ, &win) == -1)
+ twidth = 80;
+ else
+ twidth = (win.ws_col == 0 ? 80 : win.ws_col);
+
+ /* add the '-' for BSD compatibility */
+ if (argc > 1) {
+ if (argv[1][0] != '-' && !isdigit(argv[1][0])) {
+ len = strlen(argv[1]) + 2;
+ tmp = malloc(len);
+ if (tmp != NULL) {
+ (void) snprintf(tmp, len, "%s%s", "-", argv[1]);
+ argv[1] = tmp;
+ }
+ }
+ }
+
+ setbuf(stdout, stdbuf);
+ while ((c = getopt(argc, argv, "lcaengrSt:xuvwU")) != EOF)
+ switch (c) {
+ case 'g':
+ gflg++; /* include process group leaders */
+ break;
+ case 'c': /* display internal command name */
+ cflg++;
+ break;
+ case 'r': /* restrict output to running processes */
+ rflg++;
+ break;
+ case 'S': /* display time by process and all reaped children */
+ Sflg++;
+ break;
+ case 'x': /* process w/o controlling tty */
+ xflg++;
+ break;
+ case 'l': /* long listing */
+ lflg++;
+ uflg = vflg = 0;
+ break;
+ case 'u': /* user-oriented output */
+ uflg++;
+ lflg = vflg = 0;
+ break;
+ case 'U': /* update private database ups_data */
+ Uflg++;
+ break;
+ case 'w': /* increase display width */
+ if (twidth < 132)
+ twidth = 132;
+ else /* second w option */
+ twidth = NCARGS;
+ break;
+ case 'v': /* display virtual memory format */
+ vflg++;
+ lflg = uflg = 0;
+ break;
+ case 'a':
+ /*
+ * display all processes except process group
+ * leaders and processes w/o controlling tty
+ */
+ aflg++;
+ gflg++;
+ break;
+ case 'e':
+ /* Display environment along with aguments. */
+ eflg++;
+ break;
+ case 'n': /* Display numerical output */
+ nflg++;
+ break;
+ case 't': /* restrict output to named terminal */
+#define TSZ 30
+ tflg++;
+ gflg++;
+ xflg = 0;
+
+ p1 = optarg;
+ do { /* only loop through once (NTTYS = 2) */
+ parg = argbuf;
+ if (ntty >= NTTYS-1)
+ break;
+ getarg();
+ if ((p = malloc(TSZ+1)) == NULL) {
+ (void) fprintf(stderr,
+ "ps: no memory\n");
+ exit(1);
+ }
+ p[0] = '\0';
+ size = TSZ;
+ if (isdigit(*parg)) {
+ (void) strcpy(p, "tty");
+ size -= 3;
+ }
+
+ (void) strncat(p, parg, size);
+ ttyp->tdev = PRNODEV;
+ if (parg && *parg == '?')
+ xflg++;
+ else {
+ char nambuf[TSZ+6]; /* for /dev/+\0 */
+ struct stat64 s;
+ (void) strcpy(nambuf, "/dev/");
+ (void) strcat(nambuf, p);
+ if (stat64(nambuf, &s) == 0)
+ ttyp->tdev = s.st_rdev;
+ }
+ ttyp++->tname = p;
+ ntty++;
+ } while (*p1);
+ break;
+ default: /* error on ? */
+ errflg++;
+ break;
+ }
+
+ if (errflg)
+ usage();
+
+ if (optind + 1 < argc) { /* more than one additional argument */
+ (void) fprintf(stderr, "ps: too many arguments\n");
+ usage();
+ }
+
+ /*
+ * The -U option is obsolete. Attempts to use it cause ps to exit
+ * without printing anything.
+ */
+ if (Uflg)
+ exit(0);
+
+ if (optind < argc) { /* user specified a specific proc id */
+ pflg++;
+ p1 = argv[optind];
+ parg = argbuf;
+ getarg();
+ if (!num(parg)) {
+ (void) fprintf(stderr,
+ "ps: %s is an invalid non-numeric argument for a process id\n", parg);
+ usage();
+ }
+ pidsave = (pid_t)atol(parg);
+ aflg = rflg = xflg = 0;
+ gflg++;
+ }
+
+ if (tflg)
+ ttyp->tname = NULL;
+
+ /* allocate an initial guess for the number of processes */
+ entsize = 1024;
+ psent = malloc(entsize * sizeof (struct psent));
+ if (psent == NULL) {
+ (void) fprintf(stderr, "ps: no memory\n");
+ exit(1);
+ }
+ nent = 0; /* no active entries yet */
+
+ if (lflg) {
+ (void) sprintf(hdr,
+ " F UID%*s%*s %%C PRI NI SZ RSS "
+ "WCHAN S TT TIME COMMAND", pidwidth + 1, "PID",
+ pidwidth + 1, "PPID");
+ } else if (uflg) {
+ if (nflg)
+ (void) sprintf(hdr,
+ " UID%*s %%CPU %%MEM SZ RSS "
+ "TT S START TIME COMMAND",
+ pidwidth + 1, "PID");
+ else
+ (void) sprintf(hdr,
+ "USER %*s %%CPU %%MEM SZ RSS "
+ "TT S START TIME COMMAND",
+ pidwidth + 1, "PID");
+ } else if (vflg) {
+ (void) sprintf(hdr,
+ "%*s TT S TIME SIZE RSS %%CPU %%MEM "
+ "COMMAND", pidwidth + 1, "PID");
+ } else
+ (void) sprintf(hdr, "%*s TT S TIME COMMAND",
+ pidwidth + 1, "PID");
+
+ twidth = twidth - strlen(hdr) + 6;
+ (void) printf("%s\n", hdr);
+
+ if (twidth > PRARGSZ && (psargs = malloc(twidth)) == NULL) {
+ (void) fprintf(stderr, "ps: no memory\n");
+ exit(1);
+ }
+ svpsargs = psargs;
+
+ /*
+ * Determine which processes to print info about by searching
+ * the /proc directory and looking at each process.
+ */
+ if ((dirp = opendir(procdir)) == NULL) {
+ (void) fprintf(stderr, "ps: cannot open PROC directory %s\n",
+ procdir);
+ exit(1);
+ }
+
+ (void) strcpy(psname, procdir);
+ pdlen = strlen(psname);
+ psname[pdlen++] = '/';
+
+ /* for each active process --- */
+ while (dentp = readdir(dirp)) {
+ int psfd; /* file descriptor for /proc/nnnnn/psinfo */
+ int asfd; /* file descriptor for /proc/nnnnn/as */
+
+ if (dentp->d_name[0] == '.') /* skip . and .. */
+ continue;
+ (void) strcpy(psname + pdlen, dentp->d_name);
+ (void) strcpy(asname, psname);
+ (void) strcat(psname, "/psinfo");
+ (void) strcat(asname, "/as");
+retry:
+ if ((psfd = open(psname, O_RDONLY)) == -1)
+ continue;
+ asfd = -1;
+ if (psargs != NULL || eflg) {
+
+ /* now we need the proc_owner privilege */
+ (void) __priv_bracket(PRIV_ON);
+
+ asfd = open(asname, O_RDONLY);
+
+ /* drop proc_owner privilege after open */
+ (void) __priv_bracket(PRIV_OFF);
+ }
+
+ /*
+ * Get the info structure for the process
+ */
+ if (read(psfd, &info, sizeof (info)) != sizeof (info)) {
+ int saverr = errno;
+
+ (void) close(psfd);
+ if (asfd > 0)
+ (void) close(asfd);
+ if (saverr == EAGAIN)
+ goto retry;
+ if (saverr != ENOENT)
+ (void) fprintf(stderr, "ps: read() on %s: %s\n",
+ psname, err_string(saverr));
+ continue;
+ }
+ (void) close(psfd);
+
+ found = 0;
+ if (info.pr_lwp.pr_state == 0) /* can't happen? */
+ goto closeit;
+ pid = info.pr_pid;
+ ppid = info.pr_ppid;
+
+ /* Display only process from command line */
+ if (pflg) { /* pid in arg list */
+ if (pidsave == pid)
+ found++;
+ else
+ goto closeit;
+ }
+
+ /*
+ * Omit "uninteresting" processes unless 'g' option.
+ */
+ if ((ppid == 1) && !(gflg))
+ goto closeit;
+
+ /*
+ * Omit non-running processes for 'r' option
+ */
+ if (rflg &&
+ !(info.pr_lwp.pr_sname == 'O' ||
+ info.pr_lwp.pr_sname == 'R'))
+ goto closeit;
+
+ if (!found && !tflg && !aflg && info.pr_euid != my_uid)
+ goto closeit;
+
+ /*
+ * Read the args for the -w and -ww cases
+ */
+ if (asfd > 0) {
+ if ((psargs != NULL &&
+ preadargs(asfd, &info, psargs) == -1) ||
+ (eflg && preadenvs(asfd, &info, psargs) == -1)) {
+ int saverr = errno;
+
+ (void) close(asfd);
+ if (saverr == EAGAIN)
+ goto retry;
+ if (saverr != ENOENT)
+ (void) fprintf(stderr,
+ "ps: read() on %s: %s\n",
+ asname, err_string(saverr));
+ continue;
+ }
+ } else {
+ psargs = info.pr_psargs;
+ }
+
+ if (nent >= entsize) {
+ entsize *= 2;
+ psent = (struct psent *)realloc((char *)psent,
+ entsize * sizeof (struct psent));
+ if (psent == NULL) {
+ (void) fprintf(stderr, "ps: no memory\n");
+ exit(1);
+ }
+ }
+ if ((psent[nent].psinfo = malloc(sizeof (psinfo_t)))
+ == NULL) {
+ (void) fprintf(stderr, "ps: no memory\n");
+ exit(1);
+ }
+ *psent[nent].psinfo = info;
+ if (psargs == NULL)
+ psent[nent].psargs = NULL;
+ else {
+ if ((psent[nent].psargs = malloc(strlen(psargs)+1))
+ == NULL) {
+ (void) fprintf(stderr, "ps: no memory\n");
+ exit(1);
+ }
+ (void) strcpy(psent[nent].psargs, psargs);
+ }
+ psent[nent].found = found;
+ nent++;
+closeit:
+ if (asfd > 0)
+ (void) close(asfd);
+ psargs = svpsargs;
+ }
+
+ /* revert to non-privileged user */
+ (void) __priv_relinquish();
+
+ (void) closedir(dirp);
+
+ qsort((char *)psent, nent, sizeof (psent[0]), pscompare);
+
+ for (i = 0; i < nent; i++) {
+ struct psent *pp = &psent[i];
+ if (prcom(pp->found, pp->psinfo, pp->psargs)) {
+ (void) printf("\n");
+ retcode = 0;
+ }
+ }
+
+ return (retcode);
+}
+
+static void
+usage() /* print usage message and quit */
+{
+ static char usage1[] = "ps [ -aceglnrSuUvwx ] [ -t term ] [ num ]";
+
+ (void) fprintf(stderr, "usage: %s\n", usage1);
+ exit(1);
+}
+
+/*
+ * Read the process arguments from the process.
+ * This allows >PRARGSZ characters of arguments to be displayed but,
+ * unlike pr_psargs[], the process may have changed them.
+ */
+#define NARG 100
+static int
+preadargs(int pfd, psinfo_t *psinfo, char *psargs)
+{
+ off_t argvoff = (off_t)psinfo->pr_argv;
+ size_t len;
+ char *psa = psargs;
+ int bsize = twidth;
+ int narg = NARG;
+ off_t argv[NARG];
+ off_t argoff;
+ off_t nextargoff;
+ int i;
+#ifdef _LP64
+ caddr32_t argv32[NARG];
+ int is32 = (psinfo->pr_dmodel != PR_MODEL_LP64);
+#endif
+
+ if (psinfo->pr_nlwp == 0 ||
+ strcmp(psinfo->pr_lwp.pr_clname, "SYS") == 0)
+ goto out;
+
+ (void) memset(psa, 0, bsize--);
+ nextargoff = 0;
+ errno = EIO;
+ while (bsize > 0) {
+ if (narg == NARG) {
+ (void) memset(argv, 0, sizeof (argv));
+#ifdef _LP64
+ if (is32) {
+ if ((i = pread(pfd, argv32, sizeof (argv32),
+ argvoff)) <= 0) {
+ if (i == 0 || errno == EIO)
+ break;
+ return (-1);
+ }
+ for (i = 0; i < NARG; i++)
+ argv[i] = argv32[i];
+ } else
+#endif
+ if ((i = pread(pfd, argv, sizeof (argv),
+ argvoff)) <= 0) {
+ if (i == 0 || errno == EIO)
+ break;
+ return (-1);
+ }
+ narg = 0;
+ }
+ if ((argoff = argv[narg++]) == 0)
+ break;
+ if (argoff != nextargoff &&
+ (i = pread(pfd, psa, bsize, argoff)) <= 0) {
+ if (i == 0 || errno == EIO)
+ break;
+ return (-1);
+ }
+ len = strlen(psa);
+ psa += len;
+ *psa++ = ' ';
+ bsize -= len + 1;
+ nextargoff = argoff + len + 1;
+#ifdef _LP64
+ argvoff += is32? sizeof (caddr32_t) : sizeof (caddr_t);
+#else
+ argvoff += sizeof (caddr_t);
+#endif
+ }
+ while (psa > psargs && isspace(*(psa-1)))
+ psa--;
+
+out:
+ *psa = '\0';
+ if (strlen(psinfo->pr_psargs) > strlen(psargs))
+ (void) strcpy(psargs, psinfo->pr_psargs);
+
+ return (0);
+}
+
+/*
+ * Read environment variables from the process.
+ * Append them to psargs if there is room.
+ */
+static int
+preadenvs(int pfd, psinfo_t *psinfo, char *psargs)
+{
+ off_t envpoff = (off_t)psinfo->pr_envp;
+ int len;
+ char *psa;
+ char *psainit;
+ int bsize;
+ int nenv = NARG;
+ off_t envp[NARG];
+ off_t envoff;
+ off_t nextenvoff;
+ int i;
+#ifdef _LP64
+ caddr32_t envp32[NARG];
+ int is32 = (psinfo->pr_dmodel != PR_MODEL_LP64);
+#endif
+
+ psainit = psa = (psargs != NULL)? psargs : psinfo->pr_psargs;
+ len = strlen(psa);
+ psa += len;
+ bsize = twidth - len - 1;
+
+ if (bsize <= 0 || psinfo->pr_nlwp == 0 ||
+ strcmp(psinfo->pr_lwp.pr_clname, "SYS") == 0)
+ return (0);
+
+ nextenvoff = 0;
+ errno = EIO;
+ while (bsize > 0) {
+ if (nenv == NARG) {
+ (void) memset(envp, 0, sizeof (envp));
+#ifdef _LP64
+ if (is32) {
+ if ((i = pread(pfd, envp32, sizeof (envp32),
+ envpoff)) <= 0) {
+ if (i == 0 || errno == EIO)
+ break;
+ return (-1);
+ }
+ for (i = 0; i < NARG; i++)
+ envp[i] = envp32[i];
+ } else
+#endif
+ if ((i = pread(pfd, envp, sizeof (envp),
+ envpoff)) <= 0) {
+ if (i == 0 || errno == EIO)
+ break;
+ return (-1);
+ }
+ nenv = 0;
+ }
+ if ((envoff = envp[nenv++]) == 0)
+ break;
+ if (envoff != nextenvoff &&
+ (i = pread(pfd, psa+1, bsize, envoff)) <= 0) {
+ if (i == 0 || errno == EIO)
+ break;
+ return (-1);
+ }
+ *psa++ = ' ';
+ len = strlen(psa);
+ psa += len;
+ bsize -= len + 1;
+ nextenvoff = envoff + len + 1;
+#ifdef _LP64
+ envpoff += is32? sizeof (caddr32_t) : sizeof (caddr_t);
+#else
+ envpoff += sizeof (caddr_t);
+#endif
+ }
+ while (psa > psainit && isspace(*(psa-1)))
+ psa--;
+ *psa = '\0';
+
+ return (0);
+}
+
+/*
+ * getarg() finds the next argument in list and copies arg into argbuf.
+ * p1 first pts to arg passed back from getopt routine. p1 is then
+ * bumped to next character that is not a comma or blank -- p1 NULL
+ * indicates end of list.
+ */
+
+static void
+getarg()
+{
+ char *parga;
+ int c;
+
+ while ((c = *p1) != '\0' && (c == ',' || isspace(c)))
+ p1++;
+
+ parga = argbuf;
+ while ((c = *p1) != '\0' && c != ',' && !isspace(c)) {
+ if (parga < argbuf + ARGSIZ - 1)
+ *parga++ = c;
+ p1++;
+ }
+ *parga = '\0';
+
+ while ((c = *p1) != '\0' && (c == ',' || isspace(c)))
+ p1++;
+}
+
+static char *
+devlookup(dev_t ddev)
+{
+ struct devl *dp;
+ int i;
+
+ for (dp = devl, i = 0; i < ndev; dp++, i++) {
+ if (dp->ddev == ddev)
+ return (dp->dname);
+ }
+ return (NULL);
+}
+
+static char *
+devadd(char *name, dev_t ddev)
+{
+ struct devl *dp;
+ int leng, start, i;
+
+ if (ndev == maxdev) {
+ maxdev += DNINCR;
+ devl = realloc(devl, maxdev * sizeof (struct devl));
+ if (devl == NULL) {
+ (void) fprintf(stderr,
+ "ps: not enough memory for %d devices\n", maxdev);
+ exit(1);
+ }
+ }
+ dp = &devl[ndev++];
+
+ dp->ddev = ddev;
+ if (name == NULL) {
+ (void) strcpy(dp->dname, "??");
+ return (dp->dname);
+ }
+
+ leng = strlen(name);
+ /* Strip off /dev/ */
+ if (leng < DNSIZE + 4)
+ (void) strcpy(dp->dname, &name[5]);
+ else {
+ start = leng - (DNSIZE - 1);
+
+ for (i = start; i < leng && name[i] != '/'; i++)
+ ;
+ if (i == leng)
+ (void) strlcpy(dp->dname, &name[start], DNSIZE);
+ else
+ (void) strlcpy(dp->dname, &name[i+1], DNSIZE);
+ }
+ return (dp->dname);
+}
+
+/*
+ * gettty returns the user's tty number or ? if none.
+ */
+static char *
+gettty(psinfo_t *psinfo)
+{
+ extern char *_ttyname_dev(dev_t, char *, size_t);
+ char devname[TTYNAME_MAX];
+ char *retval;
+
+ if (psinfo->pr_ttydev == PRNODEV)
+ return ("?");
+
+ if ((retval = devlookup(psinfo->pr_ttydev)) != NULL)
+ return (retval);
+
+ retval = _ttyname_dev(psinfo->pr_ttydev, devname, sizeof (devname));
+
+ return (devadd(retval, psinfo->pr_ttydev));
+}
+
+/*
+ * Print percent from 16-bit binary fraction [0 .. 1]
+ * Round up .01 to .1 to indicate some small percentage (the 0x7000 below).
+ */
+static void
+prtpct(ushort_t pct)
+{
+ uint_t value = pct; /* need 32 bits to compute with */
+
+ value = ((value * 1000) + 0x7000) >> 15; /* [0 .. 1000] */
+ (void) printf("%3u.%u", value / 10, value % 10);
+}
+
+/*
+ * Print info about the process.
+ */
+static int
+prcom(int found, psinfo_t *psinfo, char *psargs)
+{
+ char *cp;
+ char *tp;
+ char *psa;
+ long tm;
+ int i, wcnt, length;
+ wchar_t wchar;
+ struct tty *ttyp;
+
+ /*
+ * If process is zombie, call print routine and return.
+ */
+ if (psinfo->pr_nlwp == 0) {
+ if (tflg && !found)
+ return (0);
+ else {
+ przom(psinfo);
+ return (1);
+ }
+ }
+
+ /*
+ * Get current terminal. If none ("?") and 'a' is set, don't print
+ * info. If 't' is set, check if term is in list of desired terminals
+ * and print it if it is.
+ */
+ i = 0;
+ tp = gettty(psinfo);
+
+ if (*tp == '?' && !found && !xflg)
+ return (0);
+
+ if (!(*tp == '?' && aflg) && tflg && !found) {
+ int match = 0;
+ char *other = NULL;
+ for (ttyp = tty; ttyp->tname != NULL; ttyp++) {
+ /*
+ * Look for a name match
+ */
+ if (strcmp(tp, ttyp->tname) == 0) {
+ match = 1;
+ break;
+ }
+ /*
+ * Look for same device under different names.
+ */
+ if ((other == NULL) &&
+ (psinfo->pr_ttydev == ttyp->tdev))
+ other = ttyp->tname;
+ }
+ if (!match) {
+ if (other == NULL)
+ return (0);
+ tp = other;
+ }
+ }
+
+ if (lflg)
+ (void) printf("%2x", psinfo->pr_flag & 0377);
+ if (uflg) {
+ if (!nflg) {
+ struct passwd *pwd;
+
+ if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
+ /* USER */
+ (void) printf("%-8.8s", pwd->pw_name);
+ else
+ /* UID */
+ (void) printf(" %7.7d", (int)psinfo->pr_euid);
+ } else {
+ (void) printf(" %5d", (int)psinfo->pr_euid); /* UID */
+ }
+ } else if (lflg)
+ (void) printf(" %5d", (int)psinfo->pr_euid); /* UID */
+
+ (void) printf("%*d", pidwidth + 1, (int)psinfo->pr_pid); /* PID */
+ if (lflg)
+ (void) printf("%*d", pidwidth + 1,
+ (int)psinfo->pr_ppid); /* PPID */
+ if (lflg)
+ (void) printf("%3d", psinfo->pr_lwp.pr_cpu & 0377); /* CP */
+ if (uflg) {
+ prtpct(psinfo->pr_pctcpu); /* %CPU */
+ prtpct(psinfo->pr_pctmem); /* %MEM */
+ }
+ if (lflg) {
+ (void) printf("%4d", psinfo->pr_lwp.pr_pri); /* PRI */
+ (void) printf("%3d", psinfo->pr_lwp.pr_nice); /* NICE */
+ }
+ if (lflg || uflg) {
+ if (psinfo->pr_flag & SSYS) /* SZ */
+ (void) printf(" 0");
+ else if (psinfo->pr_size)
+ (void) printf("%5lu", (ulong_t)psinfo->pr_size);
+ else
+ (void) printf(" ?");
+ if (psinfo->pr_flag & SSYS) /* RSS */
+ (void) printf(" 0");
+ else if (psinfo->pr_rssize)
+ (void) printf("%5lu", (ulong_t)psinfo->pr_rssize);
+ else
+ (void) printf(" ?");
+ }
+ if (lflg) { /* WCHAN */
+ if (psinfo->pr_lwp.pr_sname != 'S') {
+ (void) printf(" ");
+ } else if (psinfo->pr_lwp.pr_wchan) {
+ (void) printf(" %+8.8lx",
+ (ulong_t)psinfo->pr_lwp.pr_wchan);
+ } else {
+ (void) printf(" ?");
+ }
+ }
+ if ((tplen = strlen(tp)) > 9)
+ maxlen = twidth - tplen + 9;
+ else
+ maxlen = twidth;
+
+ if (!lflg)
+ (void) printf(" %-8.14s", tp); /* TTY */
+ (void) printf(" %c", psinfo->pr_lwp.pr_sname); /* STATE */
+ if (lflg)
+ (void) printf(" %-8.14s", tp); /* TTY */
+ if (uflg)
+ prtime(psinfo->pr_start); /* START */
+
+ /* time just for process */
+ tm = psinfo->pr_time.tv_sec;
+ if (Sflg) { /* calculate time for process and all reaped children */
+ tm += psinfo->pr_ctime.tv_sec;
+ if (psinfo->pr_time.tv_nsec + psinfo->pr_ctime.tv_nsec
+ >= 1000000000)
+ tm += 1;
+ }
+
+ (void) printf(" %2ld:%.2ld", tm / 60, tm % 60); /* TIME */
+
+ if (vflg) {
+ if (psinfo->pr_flag & SSYS) /* SZ */
+ (void) printf(" 0");
+ else if (psinfo->pr_size)
+ (void) printf("%5lu", (ulong_t)psinfo->pr_size);
+ else
+ (void) printf(" ?");
+ if (psinfo->pr_flag & SSYS) /* SZ */
+ (void) printf(" 0");
+ else if (psinfo->pr_rssize)
+ (void) printf("%5lu", (ulong_t)psinfo->pr_rssize);
+ else
+ (void) printf(" ?");
+ prtpct(psinfo->pr_pctcpu); /* %CPU */
+ prtpct(psinfo->pr_pctmem); /* %MEM */
+ }
+ if (cflg) { /* CMD */
+ wcnt = namencnt(psinfo->pr_fname, 16, maxlen);
+ (void) printf(" %.*s", wcnt, psinfo->pr_fname);
+ return (1);
+ }
+ /*
+ * PRARGSZ == length of cmd arg string.
+ */
+ if (psargs == NULL) {
+ psa = &psinfo->pr_psargs[0];
+ i = PRARGSZ;
+ tp = &psinfo->pr_psargs[PRARGSZ];
+ } else {
+ psa = psargs;
+ i = strlen(psargs);
+ tp = psa + i;
+ }
+
+ for (cp = psa; cp < tp; /* empty */) {
+ if (*cp == 0)
+ break;
+ length = mbtowc(&wchar, cp, MB_LEN_MAX);
+ if (length < 0 || !iswprint(wchar)) {
+ (void) printf(" [ %.16s ]", psinfo->pr_fname);
+ return (1);
+ }
+ cp += length;
+ }
+ wcnt = namencnt(psa, i, maxlen);
+#if 0
+ /* dumps core on really long strings */
+ (void) printf(" %.*s", wcnt, psa);
+#else
+ (void) putchar(' ');
+ (void) fwrite(psa, 1, wcnt, stdout);
+#endif
+ return (1);
+}
+
+/*
+ * Print starting time of process unless process started more than 24 hours
+ * ago, in which case the date is printed.
+ */
+static void
+prtime(timestruc_t st)
+{
+ char sttim[26];
+ static time_t tim = 0L;
+ time_t starttime;
+
+ if (tim == 0L)
+ tim = time((time_t *)0);
+ starttime = st.tv_sec;
+ if (tim - starttime > 24*60*60) {
+ (void) strftime(sttim, sizeof (sttim), "%b %d",
+ localtime(&starttime));
+ } else {
+ (void) strftime(sttim, sizeof (sttim), "%H:%M:%S",
+ localtime(&starttime));
+ }
+ (void) printf("%9.9s", sttim);
+}
+
+static void
+przom(psinfo_t *psinfo)
+{
+ long tm;
+
+ if (lflg)
+ (void) printf("%2x", psinfo->pr_flag & 0377);
+ if (uflg) {
+ struct passwd *pwd;
+
+ if ((pwd = getpwuid(psinfo->pr_euid)) != NULL)
+ (void) printf("%-8.8s", pwd->pw_name); /* USER */
+ else
+ (void) printf(" %7.7d", (int)psinfo->pr_euid); /* UID */
+ } else if (lflg)
+ (void) printf(" %5d", (int)psinfo->pr_euid); /* UID */
+
+ (void) printf("%*d", pidwidth + 1, (int)psinfo->pr_pid); /* PID */
+ if (lflg)
+ (void) printf("%*d", pidwidth + 1,
+ (int)psinfo->pr_ppid); /* PPID */
+ if (lflg)
+ (void) printf(" 0"); /* CP */
+ if (uflg) {
+ prtpct(0); /* %CPU */
+ prtpct(0); /* %MEM */
+ }
+ if (lflg) {
+ (void) printf("%4d", psinfo->pr_lwp.pr_pri); /* PRI */
+ (void) printf(" "); /* NICE */
+ }
+ if (lflg || uflg) {
+ (void) printf(" 0"); /* SZ */
+ (void) printf(" 0"); /* RSS */
+ }
+ if (lflg)
+ (void) printf(" "); /* WCHAN */
+ (void) printf(" "); /* TTY */
+ (void) printf("%c", psinfo->pr_lwp.pr_sname); /* STATE */
+ if (uflg)
+ (void) printf(" "); /* START */
+
+ /* time just for process */
+ tm = psinfo->pr_time.tv_sec;
+ if (Sflg) { /* calculate time for process and all reaped children */
+ tm += psinfo->pr_ctime.tv_sec;
+ if (psinfo->pr_time.tv_nsec + psinfo->pr_ctime.tv_nsec
+ >= 1000000000)
+ tm += 1;
+ }
+ (void) printf(" %2ld:%.2ld", tm / 60, tm % 60); /* TIME */
+
+ if (vflg) {
+ (void) printf(" 0"); /* SZ */
+ (void) printf(" 0"); /* RSS */
+ prtpct(0); /* %CPU */
+ prtpct(0); /* %MEM */
+ }
+ (void) printf(" %.*s", maxlen, " <defunct>");
+}
+
+/*
+ * Returns true iff string is all numeric.
+ */
+static int
+num(char *s)
+{
+ int c;
+
+ if (s == NULL)
+ return (0);
+ c = *s;
+ do {
+ if (!isdigit(c))
+ return (0);
+ } while ((c = *++s) != '\0');
+ return (1);
+}
+
+/*
+ * Function to compute the number of printable bytes in a multibyte
+ * command string ("internationalization").
+ */
+static int
+namencnt(char *cmd, int eucsize, int scrsize)
+{
+ int eucwcnt = 0, scrwcnt = 0;
+ int neucsz, nscrsz;
+ wchar_t wchar;
+
+ while (*cmd != '\0') {
+ if ((neucsz = mbtowc(&wchar, cmd, MB_LEN_MAX)) < 0)
+ return (8); /* default to use for illegal chars */
+ if ((nscrsz = scrwidth(wchar)) == 0)
+ return (8);
+ if (eucwcnt + neucsz > eucsize || scrwcnt + nscrsz > scrsize)
+ break;
+ eucwcnt += neucsz;
+ scrwcnt += nscrsz;
+ cmd += neucsz;
+ }
+ return (eucwcnt);
+}
+
+static int
+pscompare(const void *v1, const void *v2)
+{
+ const struct psent *p1 = v1;
+ const struct psent *p2 = v2;
+ int i;
+
+ if (uflg)
+ i = p2->psinfo->pr_pctcpu - p1->psinfo->pr_pctcpu;
+ else if (vflg)
+ i = p2->psinfo->pr_rssize - p1->psinfo->pr_rssize;
+ else
+ i = p1->psinfo->pr_ttydev - p2->psinfo->pr_ttydev;
+ if (i == 0)
+ i = p1->psinfo->pr_pid - p2->psinfo->pr_pid;
+ return (i);
+}
+
+static char *
+err_string(int err)
+{
+ static char buf[32];
+ char *str = strerror(err);
+
+ if (str == NULL)
+ (void) sprintf(str = buf, "Errno #%d", err);
+
+ return (str);
+}
diff --git a/usr/src/ucbcmd/ps/sparc/Makefile b/usr/src/ucbcmd/ps/sparc/Makefile
new file mode 100644
index 0000000000..57b893c195
--- /dev/null
+++ b/usr/src/ucbcmd/ps/sparc/Makefile
@@ -0,0 +1,66 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ucbcmd/ps/sparc/Makefile
+#
+
+PROG= ps
+
+OBJS= ps.o
+
+SRCS= $(OBJS:%.o=../%.c)
+
+include ../../Makefile.ucbcmd
+
+CFLAGS += $(CCVERBOSE)
+
+lint := LINTFLAGS = -x
+
+FILEMODE= 0555
+OWNER= root
+GROUP= sys
+
+.KEEP_STATE:
+
+%.o: ../%.c
+ $(COMPILE.c) $<
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG32)
+
+clean:
+ $(RM) $(OBJS)
+
+lint:
+ $(LINT.c) $(SRCS) $(LDLIBS)
+
+include ../../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/ps/sparcv9/Makefile b/usr/src/ucbcmd/ps/sparcv9/Makefile
new file mode 100644
index 0000000000..ff5f86cb75
--- /dev/null
+++ b/usr/src/ucbcmd/ps/sparcv9/Makefile
@@ -0,0 +1,67 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+# ucbcmd/ps/sparcv9/Makefile
+#
+
+PROG= ps
+
+OBJS= ps.o
+
+SRCS= $(OBJS:%.o=../%.c)
+
+include ../../Makefile.ucbcmd
+include ../../Makefile.ucbcmd.64
+
+CFLAGS64 += $(CCVERBOSE)
+
+lint := LINTFLAGS64 = -x -Xarch=v9
+
+FILEMODE= 0555
+OWNER= root
+GROUP= sys
+
+.KEEP_STATE:
+
+%.o: ../%.c
+ $(COMPILE.c) $<
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG64)
+
+clean:
+ $(RM) $(OBJS)
+
+lint:
+ $(LINT.c) $(SRCS) $(LDLIBS)
+
+include ../../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/req.flg b/usr/src/ucbcmd/req.flg
new file mode 100644
index 0000000000..ad93f5319c
--- /dev/null
+++ b/usr/src/ucbcmd/req.flg
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2001 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+echo_file usr/src/ucbcmd/Makefile.ucbcmd
+echo_file usr/src/ucbcmd/Makefile.ucbcmd.64
+echo_file usr/src/ucbcmd/Makefile.ucbtarg
+echo_file usr/src/cmd/Makefile.targ
+echo_file usr/src/cmd/mapfile_noexstk
+echo_file usr/src/cmd/sgs/mapfiles/sparc/map.pagealign
+echo_file usr/src/cmd/sgs/mapfiles/i386/map.pagealign
diff --git a/usr/src/ucbcmd/rusage/Makefile b/usr/src/ucbcmd/rusage/Makefile
new file mode 100644
index 0000000000..65afff3104
--- /dev/null
+++ b/usr/src/ucbcmd/rusage/Makefile
@@ -0,0 +1,56 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= rusage
+
+include ../Makefile.ucbcmd
+
+INC1 = $(ROOT)/usr/ucbinclude
+
+FILEMODE= 755
+
+LDLIBS += -L$(ROOT)/usr/ucblib -lucb
+
+#CPPFLAGS.master += -I$(INC1)
+CPPFLAGS = -I$(INC1) $(CPPFLAGS.master)
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(PROG).c
+ $(SETRUNPATH) $(LINK.c) -o $@ $(PROG).c $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
+
diff --git a/usr/src/ucbcmd/rusage/rusage.c b/usr/src/ucbcmd/rusage/rusage.c
new file mode 100644
index 0000000000..51b89a84d7
--- /dev/null
+++ b/usr/src/ucbcmd/rusage/rusage.c
@@ -0,0 +1,134 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+#ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * Copyright (c) 1988 by Sun Microsystems, Inc.
+ */
+
+/*
+ * rusage
+ */
+
+#include <locale.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+void
+fprintt(s, tv)
+ char *s;
+ struct timeval *tv;
+{
+
+ (void) fprintf(stderr, gettext("%d.%02d %s "),
+ tv->tv_sec, tv->tv_usec/10000, s);
+}
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ union wait status;
+ int options=0;
+ register int p;
+ struct timeval before, after;
+ struct rusage ru;
+ struct timezone tz;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ if (argc<=1)
+ exit(0);
+ (void) gettimeofday(&before, &tz);
+
+ /* fork a child process to run the command */
+
+ p = fork();
+ if (p < 0) {
+ perror("rusage");
+ exit(1);
+ }
+
+ if (p == 0) {
+
+ /* exec the command specified */
+
+ execvp(argv[1], &argv[1]);
+ perror(argv[1]);
+ exit(1);
+ }
+
+ /* parent code - wait for command to complete */
+
+ (void)signal(SIGINT, SIG_IGN);
+ (void)signal(SIGQUIT, SIG_IGN);
+ while (wait3(&status.w_status, options, &ru) != p)
+ ;
+
+ /* get closing time of day */
+ (void) gettimeofday(&after, &tz);
+
+ /* check for exit status of command */
+
+ if ((status.w_termsig) != 0)
+ (void) fprintf(stderr, gettext("Command terminated abnormally.\n"));
+
+ /* print an accounting summary line */
+
+ after.tv_sec -= before.tv_sec;
+ after.tv_usec -= before.tv_usec;
+ if (after.tv_usec < 0) {
+ after.tv_sec--;
+ after.tv_usec += 1000000;
+ }
+ fprintt(gettext("real"), &after);
+ fprintt(gettext("user"), &ru.ru_utime);
+ fprintt(gettext("sys"), &ru.ru_stime);
+ (void) fprintf(stderr, gettext("%d pf %d pr %d sw"),
+ ru.ru_majflt,
+ ru.ru_minflt,
+ ru.ru_nswap);
+ (void) fprintf(stderr, gettext(" %d rb %d wb %d vcx %d icx"),
+ ru.ru_inblock,
+ ru.ru_oublock,
+ ru.ru_nvcsw,
+ ru.ru_nivcsw);
+ (void) fprintf(stderr, gettext(" %d mx %d ix %d id %d is"),
+ ru.ru_maxrss,
+ ru.ru_ixrss,
+ ru.ru_idrss,
+ ru.ru_isrss);
+
+ (void) fprintf(stderr, "\n");
+ exit((int)status.w_retcode);
+ /*NOTREACHED*/
+}
+
diff --git a/usr/src/ucbcmd/sbcp/Makefile b/usr/src/ucbcmd/sbcp/Makefile
new file mode 100644
index 0000000000..23d6a5a3e7
--- /dev/null
+++ b/usr/src/ucbcmd/sbcp/Makefile
@@ -0,0 +1,68 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+PROG= sbcp
+
+include ../Makefile.ucbcmd
+
+CLEANFILES= sysent.s
+POFILE=
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOT4LIBPROG)
+
+clean:
+ $(RM) $(OBJS) $(CLEANFILES)
+
+# Preserve the relationship of libraries as they are defined in libc.so.1.9
+LIBBC= ../../lib/libbc/sparc/libc.so.1.9
+LIBUCB= ../../ucblib/libucb/sparc/libucb.so.1
+
+# need libc/sparc/inc for PIC.h
+ASFLAGS= -P -D_ASM -DPIC -K pic
+LDFLAGS= -R /usr/4lib:/usr/ucblib -e _start -G -t \
+ -zdefs -z text -zcombreloc -I /usr/lib/ld.so.1
+OBJS= sbcp.o
+LIBS= $(LDLIBS.lib) -lmapmalloc $(LIBBC) $(LIBUCB) -lnsl -laio -lc
+
+$(PROG): $(OBJS)
+ $(LDOPTS) $(LD) $(LDFLAGS) -o sbcp $(OBJS) $(LIBS)
+ $(POST_PROCESS)
+
+$(OBJS): sysent.s
+
+sysent.s: syscalls.list mksysent
+ -$(RM) sysent.s
+ sh ./mksysent > sysent.s
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/sbcp/mksysent b/usr/src/ucbcmd/sbcp/mksysent
new file mode 100644
index 0000000000..c99368e855
--- /dev/null
+++ b/usr/src/ucbcmd/sbcp/mksysent
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1993-2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+#pragma ident "%Z%%M% %I% %E% SMI"
+#
+# mksysent - generate the sysent table from the list of system calls
+#
+nawk '
+BEGIN {
+ print "#include <sys/asm_linkage.h>"
+ print "#include <sys/syscall.h>"
+ print ""
+ print "! This file is automatically generated from syscalls.list."
+ print "! Do not edit by hand or your changes will be lost."
+ print "! See mksysent and syscalls.list for details."
+ print ""
+ print " .section \".text\""
+ print " .align 4"
+ print "sysent:"
+}
+/^#/ { next; } # ignore comment lines
+{
+ f = $1;
+ if ($2 == "TRAP") {
+ printf "! %s\n", f;
+ printf "\trestore\t%%g0, SYS_%s, %%g1\n", f;
+ printf "\tta\t8\n";
+ printf "\tjmp\t%%g6\n";
+ printf "\tnop\n";
+ } else if ($2 == "SIMPLE") {
+ printf "! %s\n", f;
+ printf "\t.global\t%s\n", f;
+ printf "\tcall\t%s\n", f;
+ printf "\tnop\n";
+ printf "\tb,a\ttrap0rtn\n";
+ printf "\tnop\n";
+ } else {
+ printf "! %s\n", f;
+ printf "\tb,a\tnosys\n";
+ printf "\tnop\n";
+ printf "\tnop\n";
+ printf "\tnop\n";
+ }
+}
+' <syscalls.list
diff --git a/usr/src/ucbcmd/sbcp/sbcp.s b/usr/src/ucbcmd/sbcp/sbcp.s
new file mode 100644
index 0000000000..2cac44efe3
--- /dev/null
+++ b/usr/src/ucbcmd/sbcp/sbcp.s
@@ -0,0 +1,181 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+ .file "%M%"
+
+#include <sys/asm_linkage.h>
+#include <sys/syscall.h>
+
+#define PIC_SETUP(r) \
+ mov %o7, %g1; \
+9: call 8f; \
+ sethi %hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \
+8: or %r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \
+ add %r, %o7, %r; \
+ mov %g1, %o7
+
+#define FUNC(x) \
+ .section ".text"; \
+ .align 4; \
+ .type x, #function; \
+x:
+
+#define ENOSYS 90 /* 4.x ENOSYS */
+
+/* derived from <sys/exechdr.h>, which we can't include */
+#define A_MAGIC 0x02 /* offset of a_magic field */
+#define A_ENTRY 0x14 /* offset of a_entry field */
+#define ZMAGIC 0413 /* magic number for demand paged executable */
+
+ .global atexit, errno
+
+!
+! _start - execution starts here (after the runtime linker runs)
+!
+! The SPARC ABI defines our "environment" at this point, see page 3-34.
+! Register the exit handler, register the trap0 handler, find the
+! entry point, and jump to it. We depend on the stack (argv, envp)
+! being compatible between 4.x and 5.x. We also depend on the
+! runtime linker to set up ``environ''.
+!
+
+ENTRY_NP(_start)
+ tst %g1 ! is there a handler to register?
+ bz 1f ! no
+ nop
+ mov %g1, %o0
+ call atexit ! yes, register it with atexit()
+ nop
+1:
+
+ ! give the kernel the address of our trap0 handler
+
+ PIC_SETUP(g2)
+ ld [%g2+trap0], %g1
+ ta 9
+
+ ! jump to the main program's entry point
+
+ sethi %hi(0x2000), %o0
+ lduh [%o0 + A_MAGIC], %g1
+ cmp %g1, ZMAGIC ! is it a ZMAGIC executable?
+ be,a 1f ! yes,
+ ld [%o0 + A_ENTRY], %o0 ! get entry point
+1: ! else, assume entry point is 0x2000
+ jmp %o0
+ nop
+ SET_SIZE(_start)
+
+!
+! trap0 - glue between 4.x syscall trap and 5.x BCP routine
+!
+! enter with:
+! %g1 syscall number
+! %g6 return address (after trap instruction)
+!
+! We used to use %g7, but that conflicts with threading code
+! which uses %g7 as the curthread pointer. That is why we
+! changed to using %g6 instead.
+!
+! We use an extra window to save the %o registers we're entered
+! with (which the 4.x system call stubs depend on) and to allow
+! recursive traps (e.g., from a signal handler).
+!
+
+FUNC(trap0)
+ save %sp, -SA(MINFRAME), %sp
+ tst %g1
+ be 1f
+ nop
+ mov %i0, %o0
+ mov %i1, %o1
+ mov %i2, %o2
+ mov %i3, %o3
+ mov %i4, %o4
+ mov %i5, %o5
+ ba,a 2f
+1:
+ ! indir syscall
+ mov %i0, %g1
+ mov %i1, %o0
+ mov %i2, %o1
+ mov %i3, %o2
+ mov %i4, %o3
+ mov %i5, %o4
+ ld [%fp + MINFRAME], %o5
+2:
+ sll %g1, 4, %l1
+ PIC_SETUP(l0)
+ ld [%l0+sysent], %l0
+ add %l1, %l0, %l1
+ jmp %l1 ! jump into branch table
+ nop
+ SET_SIZE(trap0)
+
+FUNC(trap0rtn)
+ cmp %o0, -1
+ bne 1f
+ addcc %g0, %g0, %g0 ! psr &= ~C
+ PIC_SETUP(o1)
+ ld [%o1+errno], %o1
+ ld [%o1], %o0
+ subcc %g0, 1, %g0 ! psr |= C
+1:
+ mov %o0, %i0
+ restore
+ jmp %g6
+ nop
+ SET_SIZE(trap0rtn)
+
+!
+! nullsys
+!
+FUNC(nullsys)
+ clr %o0
+ b,a trap0rtn
+ SET_SIZE(nullsys)
+
+!
+! nosys
+!
+FUNC(nosys)
+ set ENOSYS, %o1
+ PIC_SETUP(g2)
+ ld [%g2+errno], %g2
+ st %o1, [%g2]
+ set -1, %o0
+ b,a trap0rtn
+ SET_SIZE(nosys)
+
+!
+! Have to #include the sysent table and stubs so that all
+! symbols referenced between here and there are "static"
+! to this module so the assembler can resolve them without
+! the linker needing to deal with them at run time.
+!
+#include "sysent.s"
diff --git a/usr/src/ucbcmd/sbcp/syscalls.list b/usr/src/ucbcmd/sbcp/syscalls.list
new file mode 100644
index 0000000000..8a53d3487c
--- /dev/null
+++ b/usr/src/ucbcmd/sbcp/syscalls.list
@@ -0,0 +1,216 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2000 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+nosys NOSYS /* 0 = 1, indir */
+exit TRAP /* 1 = 1, exit */
+fork TRAP /* 2 = 0, fork */
+read SIMPLE /* 3 = 3, read */
+write SIMPLE /* 4 = 3, write */
+open SIMPLE /* 5 = 3, open */
+close SIMPLE /* 6 = 1, close */
+wait4 SIMPLE /* 7 = 4, wait4 */
+creat SIMPLE /* 8 = 2, creat */
+link SIMPLE /* 9 = 2, link */
+unlink SIMPLE /* 10 = 1, unlink */
+execv SIMPLE /* 11 = 2, execv */
+chdir SIMPLE /* 12 = 1, chdir */
+nosys NOSYS /* 13 = 0, old time */
+mknod SIMPLE /* 14 = 3, mknod */
+chmod SIMPLE /* 15 = 2, chmod */
+chown SIMPLE /* 16 = 3, chown; now 3 args */
+brk SIMPLE /* 17 = 1, brk */
+nosys NOSYS /* 18 = 0, old stat */
+lseek SIMPLE /* 19 = 3, lseek */
+getpid TRAP /* 20 = 0, getpid */
+nosys NOSYS /* 21 = 0, old mount */
+umount SIMPLE /* 22 = 1, old umount */
+nosys NOSYS /* 23 = 0, old setuid */
+getuid TRAP /* 24 = 0, getuid */
+nosys NOSYS /* 25 = 0, old stime */
+ptrace SIMPLE /* 26 = 5, ptrace */
+nosys NOSYS /* 27 = 0, old alarm */
+nosys NOSYS /* 28 = 0, old fstat */
+nosys NOSYS /* 29 = 0, opause */
+nosys NOSYS /* 30 = 0, old utime */
+nosys NOSYS /* 31 = 0, was stty */
+nosys NOSYS /* 32 = 0, was gtty */
+access SIMPLE /* 33 = 2, access */
+nosys NOSYS /* 34 = 0, old nice */
+nosys NOSYS /* 35 = 0, old ftime */
+sync SIMPLE /* 36 = 0, sync */
+kill SIMPLE /* 37 = 2, kill */
+stat SIMPLE /* 38 = 2, stat */
+nosys NOSYS /* 39 = 0, old setpgrp */
+lstat SIMPLE /* 40 = 2, lstat */
+dup SIMPLE /* 41 = 2, dup */
+pipe TRAP /* 42 = 0, pipe */
+nosys NOSYS /* 43 = 0, old times */
+profil SIMPLE /* 44 = 4, profil */
+nosys NOSYS /* 45 = 0, nosys */
+nosys NOSYS /* 46 = 0, old setgid */
+getgid TRAP /* 47 = 0, getgid */
+nosys NOSYS /* 48 = 0, old sig */
+nosys NOSYS /* 49 = 0, reserved for USG */
+nosys NOSYS /* 50 = 0, reserved for USG */
+nosys NOSYS /* 51 = 1, turn acct off/on */
+nosys NOSYS /* 52 = 0, old set phys addr */
+mctl SIMPLE /* 53 = 4, memory control */
+ioctl SIMPLE /* 54 = 3, ioctl */
+reboot SIMPLE /* 55 = 2, reboot */
+wait3 NOSYS /* 56 = 3, wait3 (per-4.0) */
+symlink SIMPLE /* 57 = 2, symlink */
+readlink SIMPLE /* 58 = 3, readlink */
+execve SIMPLE /* 59 = 3, execve */
+umask SIMPLE /* 60 = 1, umask */
+chroot SIMPLE /* 61 = 1, chroot */
+fstat SIMPLE /* 62 = 2, fstat */
+nosys NOSYS /* 63 = 0, used internally */
+getpagesize SIMPLE /* 64 = 1, getpagesize */
+msync SIMPLE /* 65 = 3, old msync */
+vfork TRAP /* 66 = 0, vfork */
+read SIMPLE /* 67 = 0, old vread */
+write SIMPLE /* 68 = 0, old vwrite */
+sbrk SIMPLE /* 69 = 1, sbrk */
+nullsys SIMPLE /* 70 = 1, sstk (emulated as nop) */
+mmap SIMPLE /* 71 = 6, mmap */
+nullsys SIMPLE /* 72 = 1, old vadvise (emulated as nop) */
+munmap SIMPLE /* 73 = 2, munmap */
+mprotect SIMPLE /* 74 = 3, mprotect */
+madvise SIMPLE /* 75 = 3, old madvise */
+vhangup SIMPLE /* 76 = 1, vhangup */
+nosys NOSYS /* 77 = 0, old vlimit */
+mincore SIMPLE /* 78 = 3, mincore */
+getgroups SIMPLE /* 79 = 2, getgroups */
+setgroups SIMPLE /* 80 = 2, setgroups */
+getpgrp SIMPLE /* 81 = 1, getpgrp */
+setpgrp SIMPLE /* 82 = 2, setpgrp */
+setitimer SIMPLE /* 83 = 3, setitimer */
+wait NOSYS /* 84 = 0, old wait & wait3 (per-4.0) */
+nosys NOSYS /* 85 = 1, swapon */
+getitimer SIMPLE /* 86 = 2, getitimer */
+gethostname SIMPLE /* 87 = 2, gethostname */
+sethostname SIMPLE /* 88 = 2, sethostname */
+getdtablesize SIMPLE /* 89 = 0, getdtablesize */
+dup2 SIMPLE /* 90 = 2, dup2 */
+nullsys SIMPLE /* 91 = 2, getdopt (not implemented) */
+fcntl SIMPLE /* 92 = 3, fcntl */
+select SIMPLE /* 93 = 5, select */
+nullsys SIMPLE /* 94 = 2, setdopt (not implemented) */
+fsync SIMPLE /* 95 = 1, fsync */
+setpriority SIMPLE /* 96 = 3, setpriority */
+socket SIMPLE /* 97 = 3, socket */
+connect SIMPLE /* 98 = 3, connect */
+accept SIMPLE /* 99 = 3, accept */
+getpriority SIMPLE /* 100 = 2, getpriority */
+send SIMPLE /* 101 = 4, send */
+recv SIMPLE /* 102 = 4, recv */
+nosys NOSYS /* 103 = 0, old socketaddr */
+bind SIMPLE /* 104 = 3, bind */
+setsockopt SIMPLE /* 105 = 5, setsockopt */
+listen SIMPLE /* 106 = 2, listen */
+nosys NOSYS /* 107 = 0, old vtimes */
+sigvec SIMPLE /* 108 = 3, sigvec */
+sigblock SIMPLE /* 109 = 1, sigblock */
+sigsetmask SIMPLE /* 110 = 1, sigsetmask */
+sigpause SIMPLE /* 111 = 1, sigpause */
+sigstack SIMPLE /* 112 = 2, sigstack */
+recvmsg SIMPLE /* 113 = 3, recvmsg */
+sendmsg SIMPLE /* 114 = 3, sendmsg */
+nosys NOSYS /* 115 = 0, nosys */
+gettimeofday SIMPLE /* 116 = 2, gettimeofday */
+getrusage SIMPLE /* 117 = 2, getrusage */
+getsockopt SIMPLE /* 118 = 5, getsockopt */
+nosys NOSYS /* 119 = 0, nosys */
+readv SIMPLE /* 120 = 3, readv */
+writev SIMPLE /* 121 = 3, writev */
+settimeofday SIMPLE /* 122 = 2, settimeofday */
+fchown SIMPLE /* 123 = 3, fchown */
+fchmod SIMPLE /* 124 = 2, fchmod */
+recvfrom SIMPLE /* 125 = 6, recvfrom */
+setreuid SIMPLE /* 126 = 2, setreuid */
+setregid SIMPLE /* 127 = 2, setregid */
+rename SIMPLE /* 128 = 2, rename */
+truncate SIMPLE /* 129 = 2, truncate */
+ftruncate SIMPLE /* 130 = 2, ftruncate */
+flock SIMPLE /* 131 = 2, flock */
+nosys NOSYS /* 132 = 0, nosys */
+sendto SIMPLE /* 133 = 6, sendto */
+shutdown SIMPLE /* 134 = 2, shutdown */
+socketpair SIMPLE /* 135 = 5, socketpair */
+mkdir SIMPLE /* 136 = 2, mkdir */
+rmdir SIMPLE /* 137 = 1, rmdir */
+utimes SIMPLE /* 138 = 2, utimes */
+__sigcleanup SIMPLE /* 139 = 0, signalcleanup */
+adjtime SIMPLE /* 140 = 2, adjtime */
+getpeername SIMPLE /* 141 = 3, getpeername */
+gethostid SIMPLE /* 142 = 2, gethostid */
+nosys NOSYS /* 143 = 0, old sethostid */
+getrlimit SIMPLE /* 144 = 2, getrlimit */
+setrlimit SIMPLE /* 145 = 2, setrlimit */
+killpg SIMPLE /* 146 = 2, killpg */
+nosys NOSYS /* 147 = 0, nosys */
+nosys NOSYS /* 148 = 0, old quota */
+nosys NOSYS /* 149 = 0, old qquota */
+getsockname SIMPLE /* 150 = 3, getsockname */
+getmsg SIMPLE /* 151 = 4, getmsg */
+putmsg SIMPLE /* 152 = 4, putmsg */
+poll SIMPLE /* 153 = 3, poll */
+nosys NOSYS /* 154 = 0, old nfs_mount */
+nosys NOSYS /* 155 = 1, nfs_svc */
+getdirentries NOSYS /* 156 = 4, getdirentries (pre-4.0) */
+statfs SIMPLE /* 157 = 2, statfs */
+fstatfs SIMPLE /* 158 = 2, fstatfs */
+unmount SIMPLE /* 159 = 1, unmount */
+nosys NOSYS /* 160 = 0, async_daemon */
+nfs_getfh SIMPLE /* 161 = 2, get file handle */
+getdomainname SIMPLE /* 162 = 2, getdomainname */
+setdomainname SIMPLE /* 163 = 2, setdomainname */
+nosys NOSYS /* 164 = 0, not configured */
+nosys NOSYS /* 165 = 4, quotactl */
+exportfs SIMPLE /* 166 = 2, exportfs */
+mount SIMPLE /* 167 = 4, mount */
+ustat SIMPLE /* 168 = 2, ustat */
+semsys SIMPLE /* 169 = 5, semsys */
+msgsys SIMPLE /* 170 = 6, msgsys */
+shmsys SIMPLE /* 171 = 4, shmsys */
+nosys NOSYS /* 172 = 0, not configured */
+nosys NOSYS /* 173 = 0, not configured */
+getdents SIMPLE /* 174 = 3, getdents */
+setsid SIMPLE /* 175 = 1, setsid & s5 setpgrp() */
+fchdir SIMPLE /* 176 = 1, fchdir */
+fchroot SIMPLE /* 177 = 1, fchroot */
+nosys NOSYS /* 178 = 0, not configured */
+aioread SIMPLE /* 179 = 6, aioread */
+aiowrite SIMPLE /* 180 = 6, aiowrite */
+aiowait SIMPLE /* 181 = 1, aiowait */
+aiocancel SIMPLE /* 182 = 1, aiocancel */
+sigpending SIMPLE /* 183 = 1, sigpending */
+nosys NOSYS /* 184 = 0, AVAILABLE */
+setpgid SIMPLE /* 185 = 2, setpgid */
+pathconf SIMPLE /* 186 = 2, pathconf */
+fpathconf SIMPLE /* 187 = 2, fpathconf */
+sysconf SIMPLE /* 188 = 1, sysconf */
+uname SIMPLE /* 189 = 1, uname */
diff --git a/usr/src/ucbcmd/sed/Makefile b/usr/src/ucbcmd/sed/Makefile
new file mode 100644
index 0000000000..21f2d1008b
--- /dev/null
+++ b/usr/src/ucbcmd/sed/Makefile
@@ -0,0 +1,55 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright (c) 1996, by Sun Microsystems, Inc.
+# All rights reserved.
+#
+
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+
+PROG= sed
+
+OBJS= sed0.o sed1.o
+SRCS= $(OBJS:%.o=%.c)
+
+include ../Makefile.ucbcmd
+
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(LINK.c) $(OBJS) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG)
+
+clean:
+ $(RM) $(OBJS)
+
+lint: lint_SRCS
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/sed/sed.h b/usr/src/ucbcmd/sed/sed.h
new file mode 100644
index 0000000000..92ac2c0cd7
--- /dev/null
+++ b/usr/src/ucbcmd/sed/sed.h
@@ -0,0 +1,152 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1996 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984 AT&T */
+/* All Rights Reserved */
+
+#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R3.1 1.8 */
+
+/*
+ * sed -- stream editor
+ */
+
+#include <ctype.h>
+#include <locale.h>
+
+/*
+ * define some macros for rexexp.h
+ */
+
+#define INIT extern char *cp; /* cp points to RE string */\
+ register char *sp = cp;
+#define GETC() (*sp++)
+#define PEEKC() (*sp)
+#define UNGETC(c) (--sp)
+#define RETURN(c) cp = sp; return(ep);
+#define ERROR(c) regerr(c)
+
+#define CEND 16
+#define CLNUM 14
+
+#define NLINES 256
+#define DEPTH 20
+#define PTRSIZE 200
+#define RESIZE 10000
+#define ABUFSIZE 20
+#define LBSIZE 4000
+#define ESIZE 256
+#define LABSIZE 50
+
+extern union reptr *abuf[];
+extern union reptr **aptr;
+extern char genbuf[];
+extern char *lcomend;
+extern long long lnum;
+extern char linebuf[];
+extern char holdsp[];
+extern char *spend;
+extern char *hspend;
+extern int nflag;
+extern long long tlno[];
+
+#define ACOM 01
+#define BCOM 020
+#define CCOM 02
+#define CDCOM 025
+#define CNCOM 022
+#define COCOM 017
+#define CPCOM 023
+#define DCOM 03
+#define ECOM 015
+#define EQCOM 013
+#define FCOM 016
+#define GCOM 027
+#define CGCOM 030
+#define HCOM 031
+#define CHCOM 032
+#define ICOM 04
+#define LCOM 05
+#define NCOM 012
+#define PCOM 010
+#define QCOM 011
+#define RCOM 06
+#define SCOM 07
+#define TCOM 021
+#define WCOM 014
+#define CWCOM 024
+#define YCOM 026
+#define XCOM 033
+
+
+union reptr {
+ struct reptr1 {
+ char *ad1;
+ char *ad2;
+ char *re1;
+ char *rhs;
+ FILE *fcode;
+ char command;
+ int gfl;
+ char pfl;
+ char inar;
+ char negfl;
+ } r1;
+ struct reptr2 {
+ char *ad1;
+ char *ad2;
+ union reptr *lb1;
+ char *rhs;
+ FILE *fcode;
+ char command;
+ int gfl;
+ char pfl;
+ char inar;
+ char negfl;
+ } r2;
+};
+extern union reptr ptrspace[];
+
+
+
+struct label {
+ char asc[9];
+ union reptr *chain;
+ union reptr *address;
+};
+
+
+
+extern int eargc;
+
+extern union reptr *pending;
+char *compile();
+char *ycomp();
+char *address();
+char *text();
+char *compsub();
+struct label *search();
+char *gline();
+char *place();
diff --git a/usr/src/ucbcmd/sed/sed0.c b/usr/src/ucbcmd/sed/sed0.c
new file mode 100644
index 0000000000..e8d46ea2c5
--- /dev/null
+++ b/usr/src/ucbcmd/sed/sed0.c
@@ -0,0 +1,868 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1996, by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* from S5R3.1 1.10 */
+
+#include <stdio.h>
+#include <sys/param.h>
+#include "sed.h"
+#define NWFILES 11 /* 10 plus one for standard output */
+FILE *fin;
+FILE *fcode[NWFILES];
+char *lastre;
+char sseof;
+union reptr *ptrend;
+int eflag;
+extern nbra;
+char linebuf[LBSIZE+1];
+int gflag;
+int nlno;
+char *fname[NWFILES];
+int nfiles;
+union reptr ptrspace[PTRSIZE];
+union reptr *rep;
+char *cp;
+char respace[RESIZE];
+struct label ltab[LABSIZE];
+struct label *lab;
+struct label *labend;
+int depth;
+int eargc;
+char **eargv;
+union reptr **cmpend[DEPTH];
+
+#define CCEOF 22
+
+struct label *labtab = ltab;
+
+char ETMES[] = "Extra text at end of command: %s";
+char SMMES[] = "Space missing before filename: %s";
+char TMMES[] = "Too much command text: %s";
+char LTL[] = "Label too long: %s";
+char AD0MES[] = "No addresses allowed: %s";
+char AD1MES[] = "Only one address allowed: %s";
+char TOOBIG[] = "Suffix too large - 512 max: %s";
+
+extern sed; /* IMPORTANT flag !!! */
+extern char *comple();
+
+extern char *malloc();
+
+main(argc, argv)
+char *argv[];
+{
+ int flag_found = 0;
+
+ sed = 1;
+ eargc = argc;
+ eargv = argv;
+
+ aptr = abuf;
+ lab = labtab + 1; /* 0 reserved for end-pointer */
+ rep = ptrspace;
+ rep->r1.ad1 = respace;
+ lcomend = &genbuf[71];
+ ptrend = &ptrspace[PTRSIZE];
+ labend = &labtab[LABSIZE];
+ lnum = 0;
+ pending = 0;
+ depth = 0;
+ spend = linebuf;
+ hspend = holdsp; /* Avoid "bus error" under "H" cmd. */
+ fcode[0] = stdout;
+ fname[0] = "";
+ nfiles = 1;
+
+ if(eargc == 1)
+ exit(0);
+
+
+ setlocale(LC_ALL, ""); /* get locale environment */
+
+ while (--eargc > 0 && (++eargv)[0][0] == '-')
+ switch (eargv[0][1]) {
+
+ case 'n':
+ nflag++;
+ continue;
+
+ case 'f':
+ flag_found = 1;
+ if(eargc-- <= 0) exit(2);
+
+ if((fin = fopen(*++eargv, "r")) == NULL) {
+ (void) fprintf(stderr, "sed: ");
+ perror(*eargv);
+ exit(2);
+ }
+
+ fcomp();
+ (void) fclose(fin);
+ continue;
+
+ case 'e':
+ flag_found = 1;
+ eflag++;
+ fcomp();
+ eflag = 0;
+ continue;
+
+ case 'g':
+ gflag++;
+ continue;
+
+ default:
+ (void) fprintf(stderr, "sed: Unknown flag: %c\n", eargv[0][1]);
+ exit(2);
+ }
+
+
+ if(rep == ptrspace && !flag_found) {
+ eargv--;
+ eargc++;
+ eflag++;
+ fcomp();
+ eargv++;
+ eargc--;
+ eflag = 0;
+ }
+
+ if(depth)
+ comperr("Too many {'s");
+
+ labtab->address = rep;
+
+ dechain();
+
+ if(eargc <= 0)
+ execute((char *)NULL);
+ else while(--eargc >= 0) {
+ execute(*eargv++);
+ }
+ (void) fclose(stdout);
+ exit(0);
+ /*NOTREACHED*/
+}
+
+fcomp()
+{
+
+ register char *p, *op, *tp;
+ char *address();
+ union reptr *pt, *pt1;
+ int i, ii;
+ struct label *lpt;
+ char fnamebuf[MAXPATHLEN];
+
+ op = lastre;
+
+ if(rline(linebuf, &linebuf[LBSIZE+1]) < 0) return;
+ if(*linebuf == '#') {
+ if(linebuf[1] == 'n')
+ nflag = 1;
+ }
+ else {
+ cp = linebuf;
+ goto comploop;
+ }
+
+ for(;;) {
+ if(rline(linebuf, &linebuf[LBSIZE+1]) < 0) break;
+
+ cp = linebuf;
+
+comploop:
+/* (void) fprintf(stderr, "cp: %s\n", cp); /*DEBUG*/
+ while(*cp == ' ' || *cp == '\t') cp++;
+ if(*cp == '\0' || *cp == '#') continue;
+ if(*cp == ';') {
+ cp++;
+ goto comploop;
+ }
+
+ p = address(rep->r1.ad1);
+
+ if(p == rep->r1.ad1) {
+ if(op)
+ rep->r1.ad1 = op;
+ else
+ comperr("First RE may not be null: %s");
+ } else if(p == 0) {
+ p = rep->r1.ad1;
+ rep->r1.ad1 = 0;
+ } else {
+ op = rep->r1.ad1;
+ if(*cp == ',' || *cp == ';') {
+ cp++;
+ rep->r1.ad2 = p;
+ p = address(rep->r1.ad2);
+ if(p == 0)
+ comperr("Illegal line number: %s");
+ if(p == rep->r1.ad2)
+ rep->r1.ad2 = op;
+ else
+ op = rep->r1.ad2;
+
+ } else
+ rep->r1.ad2 = 0;
+ }
+
+ if(p > &respace[RESIZE-1])
+ comperr(TMMES);
+
+ while(*cp == ' ' || *cp == '\t') cp++;
+
+swit:
+ switch(*cp++) {
+
+ default:
+ comperr("Unrecognized command: %s");
+
+ case '!':
+ rep->r1.negfl = 1;
+ goto swit;
+
+ case '{':
+ rep->r1.command = BCOM;
+ rep->r1.negfl = !(rep->r1.negfl);
+ cmpend[depth++] = &rep->r2.lb1;
+ if(++rep >= ptrend)
+ comperr("Too many commands: %s");
+ rep->r1.ad1 = p;
+ if(*cp == '\0') continue;
+
+ goto comploop;
+
+ case '}':
+ if(rep->r1.ad1)
+ comperr(AD0MES);
+
+ if(--depth < 0)
+ comperr("Too many }'s");
+ *cmpend[depth] = rep;
+
+ rep->r1.ad1 = p;
+ continue;
+
+ case '=':
+ rep->r1.command = EQCOM;
+ if(rep->r1.ad2)
+ comperr(AD1MES);
+ break;
+
+ case ':':
+ if(rep->r1.ad1)
+ comperr(AD0MES);
+
+ while(*cp++ == ' ');
+ cp--;
+
+
+ tp = lab->asc;
+ while((*tp++ = *cp++))
+ if(tp >= &(lab->asc[8]))
+ comperr(LTL);
+ *--tp = '\0';
+
+ if(lpt = search(lab)) {
+ if(lpt->address)
+ comperr("Duplicate labels: %s");
+ } else {
+ lab->chain = 0;
+ lpt = lab;
+ if(++lab >= labend)
+ comperr("Too many labels: %s");
+ }
+ lpt->address = rep;
+ rep->r1.ad1 = p;
+
+ continue;
+
+ case 'a':
+ rep->r1.command = ACOM;
+ if(rep->r1.ad2)
+ comperr(AD1MES);
+ if(*cp == '\\') cp++;
+ if(*cp++ != '\n')
+ comperr(ETMES);
+ rep->r1.re1 = p;
+ if ((p = text(rep->r1.re1, &respace[RESIZE-1])) == NULL)
+ comperr(TMMES);
+ break;
+ case 'c':
+ rep->r1.command = CCOM;
+ if(*cp == '\\') cp++;
+ if(*cp++ != ('\n'))
+ comperr(ETMES);
+ rep->r1.re1 = p;
+ if ((p = text(rep->r1.re1, &respace[RESIZE-1])) == NULL)
+ comperr(TMMES);
+ break;
+ case 'i':
+ rep->r1.command = ICOM;
+ if(rep->r1.ad2)
+ comperr(AD1MES);
+ if(*cp == '\\') cp++;
+ if(*cp++ != ('\n'))
+ comperr(ETMES);
+ rep->r1.re1 = p;
+ if ((p = text(rep->r1.re1, &respace[RESIZE-1])) == NULL)
+ comperr(TMMES);
+ break;
+
+ case 'g':
+ rep->r1.command = GCOM;
+ break;
+
+ case 'G':
+ rep->r1.command = CGCOM;
+ break;
+
+ case 'h':
+ rep->r1.command = HCOM;
+ break;
+
+ case 'H':
+ rep->r1.command = CHCOM;
+ break;
+
+ case 't':
+ rep->r1.command = TCOM;
+ goto jtcommon;
+
+ case 'b':
+ rep->r1.command = BCOM;
+jtcommon:
+ while(*cp++ == ' ');
+ cp--;
+
+ if(*cp == '\0') {
+ if(pt = labtab->chain) {
+ while(pt1 = pt->r2.lb1)
+ pt = pt1;
+ pt->r2.lb1 = rep;
+ } else
+ labtab->chain = rep;
+ break;
+ }
+ tp = lab->asc;
+ while((*tp++ = *cp++))
+ if(tp >= &(lab->asc[8]))
+ comperr(LTL);
+ cp--;
+ *--tp = '\0';
+
+ if(lpt = search(lab)) {
+ if(lpt->address) {
+ rep->r2.lb1 = lpt->address;
+ } else {
+ pt = lpt->chain;
+ while(pt1 = pt->r2.lb1)
+ pt = pt1;
+ pt->r2.lb1 = rep;
+ }
+ } else {
+ lab->chain = rep;
+ lab->address = 0;
+ if(++lab >= labend)
+ comperr("Too many labels: %s");
+ }
+ break;
+
+ case 'n':
+ rep->r1.command = NCOM;
+ break;
+
+ case 'N':
+ rep->r1.command = CNCOM;
+ break;
+
+ case 'p':
+ rep->r1.command = PCOM;
+ break;
+
+ case 'P':
+ rep->r1.command = CPCOM;
+ break;
+
+ case 'r':
+ rep->r1.command = RCOM;
+ if(rep->r1.ad2)
+ comperr(AD1MES);
+ if(*cp++ != ' ')
+ comperr(SMMES);
+ rep->r1.re1 = p;
+ if ((p = text(rep->r1.re1, &respace[RESIZE-1])) == NULL)
+ comperr(TMMES);
+ break;
+
+ case 'd':
+ rep->r1.command = DCOM;
+ break;
+
+ case 'D':
+ rep->r1.command = CDCOM;
+ rep->r2.lb1 = ptrspace;
+ break;
+
+ case 'q':
+ rep->r1.command = QCOM;
+ if(rep->r1.ad2)
+ comperr(AD1MES);
+ break;
+
+ case 'l':
+ rep->r1.command = LCOM;
+ break;
+
+ case 's':
+ rep->r1.command = SCOM;
+ sseof = *cp++;
+ rep->r1.re1 = p;
+ p = comple((char *) 0, rep->r1.re1, &respace[RESIZE-1], sseof);
+ if(p == rep->r1.re1) {
+ if(op)
+ rep->r1.re1 = op;
+ else
+ comperr("First RE may not be null: %s");
+ } else
+ op = rep->r1.re1;
+ rep->r1.rhs = p;
+
+ p = compsub(rep->r1.rhs);
+
+ if(*cp == 'g') {
+ cp++;
+ rep->r1.gfl = 999;
+ } else if(gflag)
+ rep->r1.gfl = 999;
+
+ if(*cp >= '1' && *cp <= '9')
+ {i = *cp - '0';
+ cp++;
+ while(1)
+ {ii = *cp;
+ if(ii < '0' || ii > '9') break;
+ i = i*10 + ii - '0';
+ if(i > 512)
+ comperr(TOOBIG);
+ cp++;
+ }
+ rep->r1.gfl = i;
+ }
+
+ if(*cp == 'p') {
+ cp++;
+ rep->r1.pfl = 1;
+ }
+
+ if(*cp == 'P') {
+ cp++;
+ rep->r1.pfl = 2;
+ }
+
+ if(*cp == 'w') {
+ cp++;
+ if(*cp++ != ' ')
+ comperr(SMMES);
+ if (text(fnamebuf, &fnamebuf[MAXPATHLEN]) == NULL)
+ comperr("File name too long: %s");
+ for(i = nfiles - 1; i >= 0; i--)
+ if(strcmp(fnamebuf,fname[i]) == 0) {
+ rep->r1.fcode = fcode[i];
+ goto done;
+ }
+ if(nfiles >= NWFILES)
+ comperr("Too many files in w commands: %s");
+
+ i = strlen(fnamebuf) + 1;
+ if ((fname[nfiles] = malloc((unsigned)i)) == NULL) {
+ (void) fprintf(stderr, "sed: Out of memory\n");
+ exit(2);
+ }
+ (void) strcpy(fname[nfiles], fnamebuf);
+ if((rep->r1.fcode = fopen(fname[nfiles], "w")) == NULL) {
+ (void) fprintf(stderr, "sed: Cannot open ");
+ perror(fname[nfiles]);
+ exit(2);
+ }
+ fcode[nfiles++] = rep->r1.fcode;
+ }
+ break;
+
+ case 'w':
+ rep->r1.command = WCOM;
+ if(*cp++ != ' ')
+ comperr(SMMES);
+ if (text(fnamebuf, &fnamebuf[MAXPATHLEN]) == NULL)
+ comperr("File name too long: %s");
+ for(i = nfiles - 1; i >= 0; i--)
+ if(strcmp(fnamebuf, fname[i]) == 0) {
+ rep->r1.fcode = fcode[i];
+ goto done;
+ }
+ if(nfiles >= NWFILES)
+ comperr("Too many files in w commands: %s");
+
+ i = strlen(fnamebuf) + 1;
+ if ((fname[nfiles] = malloc((unsigned)i)) == NULL) {
+ (void) fprintf(stderr, "sed: Out of memory\n");
+ exit(2);
+ }
+ (void) strcpy(fname[nfiles], fnamebuf);
+ if((rep->r1.fcode = fopen(fname[nfiles], "w")) == NULL) {
+ (void) fprintf(stderr, "sed: Cannot create ");
+ perror(fname[nfiles]);
+ exit(2);
+ }
+ fcode[nfiles++] = rep->r1.fcode;
+ break;
+
+ case 'x':
+ rep->r1.command = XCOM;
+ break;
+
+ case 'y':
+ rep->r1.command = YCOM;
+ sseof = *cp++;
+ rep->r1.re1 = p;
+ p = ycomp(rep->r1.re1);
+ break;
+
+ }
+done:
+ if(++rep >= ptrend)
+ comperr("Too many commands, last: %s");
+
+ rep->r1.ad1 = p;
+
+ if(*cp++ != '\0') {
+ if(cp[-1] == ';')
+ goto comploop;
+ comperr(ETMES);
+ }
+ }
+ rep->r1.command = 0;
+ lastre = op;
+}
+char *compsub(rhsbuf)
+char *rhsbuf;
+{
+ register char *p, *q;
+
+ p = rhsbuf;
+ q = cp;
+ for(;;) {
+ if(p > &respace[RESIZE-1])
+ comperr(TMMES);
+ if((*p = *q++) == '\\') {
+ p++;
+ if(p > &respace[RESIZE-1])
+ comperr(TMMES);
+ *p = *q++;
+ if(*p > nbra + '0' && *p <= '9')
+ comperr("``\\digit'' out of range: %s");
+ p++;
+ continue;
+ }
+ if(*p == sseof) {
+ *p++ = '\0';
+ cp = q;
+ return(p);
+ }
+ if(*p++ == '\0')
+ comperr("Ending delimiter missing on substitution: %s");
+
+ }
+}
+
+rline(lbuf, lbend)
+char *lbuf;
+char *lbend;
+{
+ register char *p, *q;
+ register t;
+ static char *saveq;
+
+ p = lbuf;
+
+ if(eflag) {
+ if(eflag > 0) {
+ eflag = -1;
+ if(--eargc <= 0)
+ exit(2);
+ q = *++eargv;
+ while((t = *q++) != '\0') {
+ if(t == '\n') {
+ saveq = q;
+ goto out1;
+ }
+ if (p < lbend)
+ *p++ = t;
+ if(t == '\\') {
+ if((t = *q++) == '\0') {
+ saveq = 0;
+ return(-1);
+ }
+ if (p < lbend)
+ *p++ = t;
+ }
+ }
+ saveq = 0;
+
+ out1:
+ if (p == lbend)
+ comperr("Command line too long");
+ *p = '\0';
+ return(1);
+ }
+ if((q = saveq) == 0) return(-1);
+
+ while((t = *q++) != '\0') {
+ if(t == '\n') {
+ saveq = q;
+ goto out2;
+ }
+ if(p < lbend)
+ *p++ = t;
+ if(t == '\\') {
+ if((t = *q++) == '\0') {
+ saveq = 0;
+ return(-1);
+ }
+ if (p < lbend)
+ *p++ = t;
+ }
+ }
+ saveq = 0;
+
+ out2:
+ if (p == lbend)
+ comperr("Command line too long");
+ *p = '\0';
+ return(1);
+ }
+
+ while((t = getc(fin)) != EOF) {
+ if(t == '\n') {
+ if (p == lbend)
+ comperr("Command line too long");
+ *p = '\0';
+ return(1);
+ }
+ if (p < lbend)
+ *p++ = t;
+ if(t == '\\') {
+ if((t = getc(fin)) == EOF)
+ break;
+ if(p < lbend)
+ *p++ = t;
+ }
+ }
+ if(ferror(fin)) {
+ perror("sed: Error reading pattern file");
+ exit(2);
+ }
+ return(-1);
+}
+
+char *address(expbuf)
+char *expbuf;
+{
+ register char *rcp;
+ long long lno;
+
+ if(*cp == '$') {
+ if (expbuf > &respace[RESIZE-2])
+ comperr(TMMES);
+ cp++;
+ *expbuf++ = CEND;
+ *expbuf++ = CCEOF;
+ return(expbuf);
+ }
+ if (*cp == '/' || *cp == '\\' ) {
+ if ( *cp == '\\' )
+ cp++;
+ sseof = *cp++;
+ return(comple((char *) 0, expbuf, &respace[RESIZE-1], sseof));
+ }
+
+ rcp = cp;
+ lno = 0;
+
+ while(*rcp >= '0' && *rcp <= '9')
+ lno = lno*10 + *rcp++ - '0';
+
+ if(rcp > cp) {
+ if (expbuf > &respace[RESIZE-3])
+ comperr(TMMES);
+ *expbuf++ = CLNUM;
+ *expbuf++ = nlno;
+ tlno[nlno++] = lno;
+ if(nlno >= NLINES)
+ comperr("Too many line numbers: %s");
+ *expbuf++ = CCEOF;
+ cp = rcp;
+ return(expbuf);
+ }
+ return(0);
+}
+
+char *text(textbuf, tbend)
+char *textbuf;
+char *tbend;
+{
+ register char *p, *q;
+
+ p = textbuf;
+ q = cp;
+#ifndef S5EMUL
+ /*
+ * Strip off indentation from text to be inserted.
+ */
+ while(*q == '\t' || *q == ' ') q++;
+#endif
+ for(;;) {
+
+ if(p > tbend)
+ return(NULL); /* overflowed the buffer */
+ if((*p = *q++) == '\\')
+ *p = *q++;
+ if(*p == '\0') {
+ cp = --q;
+ return(++p);
+ }
+#ifndef S5EMUL
+ /*
+ * Strip off indentation from text to be inserted.
+ */
+ if(*p == '\n') {
+ while(*q == '\t' || *q == ' ') q++;
+ }
+#endif
+ p++;
+ }
+}
+
+
+struct label *search(ptr)
+struct label *ptr;
+{
+ struct label *rp;
+
+ rp = labtab;
+ while(rp < ptr) {
+ if(strcmp(rp->asc, ptr->asc) == 0)
+ return(rp);
+ rp++;
+ }
+
+ return(0);
+}
+
+
+dechain()
+{
+ struct label *lptr;
+ union reptr *rptr, *trptr;
+
+ for(lptr = labtab; lptr < lab; lptr++) {
+
+ if(lptr->address == 0) {
+ (void) fprintf(stderr, "sed: Undefined label: %s\n", lptr->asc);
+ exit(2);
+ }
+
+ if(lptr->chain) {
+ rptr = lptr->chain;
+ while(trptr = rptr->r2.lb1) {
+ rptr->r2.lb1 = lptr->address;
+ rptr = trptr;
+ }
+ rptr->r2.lb1 = lptr->address;
+ }
+ }
+}
+
+char *ycomp(expbuf)
+char *expbuf;
+{
+ register char c;
+ register char *ep, *tsp;
+ register int i;
+ char *sp;
+
+ ep = expbuf;
+ if(ep + 0377 > &respace[RESIZE-1])
+ comperr(TMMES);
+ sp = cp;
+ for(tsp = cp; (c = *tsp) != sseof; tsp++) {
+ if(c == '\\')
+ tsp++;
+ if(c == '\0' || c == '\n')
+ comperr("Ending delimiter missing on string: %s");
+ }
+ tsp++;
+
+ while((c = *sp++) != sseof) {
+ c &= 0377;
+ if(c == '\\' && *sp == 'n') {
+ sp++;
+ c = '\n';
+ }
+ if((ep[c] = *tsp++) == '\\' && *tsp == 'n') {
+ ep[c] = '\n';
+ tsp++;
+ }
+ if(ep[c] == sseof || ep[c] == '\0')
+ comperr("Transform strings not the same size: %s");
+ }
+ if(*tsp != sseof) {
+ if(*tsp == '\0')
+ comperr("Ending delimiter missing on string: %s");
+ else
+ comperr("Transform strings not the same size: %s");
+ }
+ cp = ++tsp;
+
+ for(i = 0; i < 0400; i++)
+ if(ep[i] == 0)
+ ep[i] = i;
+
+ return(ep + 0400);
+}
+comperr(msg)
+char *msg;
+{
+ (void) fprintf(stderr, "sed: ");
+ (void) fprintf(stderr, msg, linebuf);
+ (void) putc('\n', stderr);
+ exit(2);
+}
diff --git a/usr/src/ucbcmd/sed/sed1.c b/usr/src/ucbcmd/sed/sed1.c
new file mode 100644
index 0000000000..49835169dd
--- /dev/null
+++ b/usr/src/ucbcmd/sed/sed1.c
@@ -0,0 +1,751 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* Copyright (c) 1984 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1996, by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* from S5R3.1 1.7 */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "sed.h"
+#include <regexp.h>
+
+union reptr *abuf[ABUFSIZE+1];
+union reptr **aptr;
+char ibuf[BUFSIZ];
+char *cbp;
+char *ebp;
+char genbuf[LBSIZE+1];
+char *lcomend;
+int dolflag;
+int sflag;
+int jflag;
+int delflag;
+long long lnum;
+char holdsp[LBSIZE+1];
+char *spend;
+char *hspend;
+int nflag;
+long long tlno[NLINES];
+int f;
+char *ifname;
+int numpass;
+union reptr *pending;
+char *trans[040] = {
+ "\\01",
+ "\\02",
+ "\\03",
+ "\\04",
+ "\\05",
+ "\\06",
+ "\\07",
+ "-<",
+ "->",
+ "\n",
+ "\\13",
+ "\\14",
+ "\\15",
+ "\\16",
+ "\\17",
+ "\\20",
+ "\\21",
+ "\\22",
+ "\\23",
+ "\\24",
+ "\\25",
+ "\\26",
+ "\\27",
+ "\\30",
+ "\\31",
+ "\\32",
+ "\\33",
+ "\\34",
+ "\\35",
+ "\\36",
+ "\\37"
+};
+char rub[] = {"\\177"};
+
+extern char TMMES[];
+
+execute(file)
+char *file;
+{
+ register char *p1, *p2;
+ register union reptr *ipc;
+ int c;
+ char *execp;
+
+ if (file) {
+ if ((f = open(file, 0)) < 0) {
+ (void) fprintf(stderr, "sed: ");
+ perror(file);
+ }
+ ifname = file;
+ } else {
+ f = 0;
+ ifname = "standard input";
+ }
+
+ ebp = ibuf;
+ cbp = ibuf;
+
+ if(pending) {
+ ipc = pending;
+ pending = 0;
+ goto yes;
+ }
+
+ for(;;) {
+ if((execp = gline(linebuf)) == 0) {
+ (void) close(f);
+ return;
+ }
+ spend = execp;
+
+ for(ipc = ptrspace; ipc->r1.command; ) {
+
+ p1 = ipc->r1.ad1;
+ p2 = ipc->r1.ad2;
+
+ if(p1) {
+
+ if(ipc->r1.inar) {
+ if(*p2 == CEND) {
+ p1 = 0;
+ } else if(*p2 == CLNUM) {
+ c = (unsigned char)p2[1];
+ if(lnum > tlno[c]) {
+ ipc->r1.inar = 0;
+ if(ipc->r1.negfl)
+ goto yes;
+ ipc++;
+ continue;
+ }
+ if(lnum == tlno[c]) {
+ ipc->r1.inar = 0;
+ }
+ } else if(match(p2, 0)) {
+ ipc->r1.inar = 0;
+ }
+ } else if(*p1 == CEND) {
+ if(!dolflag) {
+ if(ipc->r1.negfl)
+ goto yes;
+ ipc++;
+ continue;
+ }
+
+ } else if(*p1 == CLNUM) {
+ c = (unsigned char)p1[1];
+ if(lnum != tlno[c]) {
+ if(ipc->r1.negfl)
+ goto yes;
+ ipc++;
+ continue;
+ }
+ if(p2)
+ ipc->r1.inar = 1;
+ } else if(match(p1, 0)) {
+ if(p2)
+ ipc->r1.inar = 1;
+ } else {
+ if(ipc->r1.negfl)
+ goto yes;
+ ipc++;
+ continue;
+ }
+ }
+
+ if(ipc->r1.negfl) {
+ ipc++;
+ continue;
+ }
+ yes:
+ command(ipc);
+
+ if(delflag)
+ break;
+
+ if(jflag) {
+ jflag = 0;
+ if((ipc = ipc->r2.lb1) == 0) {
+ ipc = ptrspace;
+ break;
+ }
+ } else
+ ipc++;
+
+ }
+ if(!nflag && !delflag) {
+ for(p1 = linebuf; p1 < spend; p1++)
+ (void) putc(*p1, stdout);
+ (void) putc('\n', stdout);
+ }
+
+ if(aptr > abuf) {
+ arout();
+ }
+
+ delflag = 0;
+
+ }
+}
+match(expbuf, gf)
+char *expbuf;
+{
+ register char *p1;
+
+ if(gf) {
+ if(*expbuf) return(0);
+ locs = p1 = loc2;
+ } else {
+ p1 = linebuf;
+ locs = 0;
+ }
+
+ circf = *expbuf++;
+ return(step(p1, expbuf));
+}
+
+substitute(ipc)
+union reptr *ipc;
+{
+ if(match(ipc->r1.re1, 0) == 0) return(0);
+
+ numpass = 0;
+ sflag = 0; /* Flags if any substitution was made */
+ dosub(ipc->r1.rhs, ipc->r1.gfl);
+
+ if(ipc->r1.gfl) {
+ while(*loc2) {
+ if(match(ipc->r1.re1, 1) == 0) break;
+ dosub(ipc->r1.rhs, ipc->r1.gfl);
+ }
+ }
+ return(sflag);
+}
+
+dosub(rhsbuf,n)
+char *rhsbuf;
+int n;
+{
+ register char *lp, *sp, *rp;
+ int c;
+
+ if(n > 0 && n < 999)
+ {numpass++;
+ if(n != numpass) return;
+ }
+ sflag = 1;
+ lp = linebuf;
+ sp = genbuf;
+ rp = rhsbuf;
+ while (lp < loc1)
+ *sp++ = *lp++;
+ while(c = *rp++) {
+ if (c == '&')
+ sp = place(sp, loc1, loc2);
+ else if (c == '\\') {
+ c = *rp++;
+ if (c >= '1' && c < NBRA+'1')
+ sp = place(sp, braslist[c-'1'], braelist[c-'1']);
+ else
+ *sp++ = c;
+ } else
+ *sp++ = c;
+ if (sp == &genbuf[LBSIZE+1]) {
+ (void) fprintf(stderr, "Output line too long.\n");
+ *--sp = '\0';
+ goto out;
+ }
+ }
+ lp = loc2;
+ loc2 = sp - genbuf + linebuf;
+ while(*sp++ = *lp++)
+ if (sp == &genbuf[LBSIZE+1]) {
+ (void) fprintf(stderr, "Output line too long.\n");
+ *--sp = '\0';
+ break;
+ }
+out:
+ lp = linebuf;
+ sp = genbuf;
+ while (*lp++ = *sp++);
+ spend = lp-1;
+}
+
+char *place(asp, al1, al2)
+char *asp, *al1, *al2;
+{
+ register char *sp, *l1, *l2;
+
+ sp = asp;
+ l1 = al1;
+ l2 = al2;
+ while (l1 < l2) {
+ *sp++ = *l1++;
+ if (sp == &genbuf[LBSIZE+1])
+ break;
+ }
+ return(sp);
+}
+
+command(ipc)
+union reptr *ipc;
+{
+ register int i;
+ register char *p1, *p2, *p3;
+ char *execp;
+
+
+ switch(ipc->r1.command) {
+
+ case ACOM:
+ if(aptr >= &abuf[ABUFSIZE]) {
+ (void) fprintf(stderr, "Too many appends or reads after line %lld\n",
+ lnum);
+ } else {
+ *aptr++ = ipc;
+ *aptr = 0;
+ }
+ break;
+
+ case CCOM:
+ delflag = 1;
+ if(!ipc->r1.inar || dolflag) {
+ for(p1 = ipc->r1.re1; *p1; )
+ (void) putc(*p1++, stdout);
+ (void) putc('\n', stdout);
+ }
+ break;
+ case DCOM:
+ delflag++;
+ break;
+ case CDCOM:
+ p1 = p2 = linebuf;
+
+ while(*p1 != '\n') {
+ if(*p1++ == 0) {
+ delflag++;
+ return;
+ }
+ }
+
+ p1++;
+ while(*p2++ = *p1++);
+ spend = p2-1;
+ jflag++;
+ break;
+
+ case EQCOM:
+ (void) fprintf(stdout, "%lld\n", lnum);
+ break;
+
+ case GCOM:
+ p1 = linebuf;
+ p2 = holdsp;
+ while(*p1++ = *p2++);
+ spend = p1-1;
+ break;
+
+ case CGCOM:
+ *spend++ = '\n';
+ p1 = spend;
+ p2 = holdsp;
+ do {
+ if (p1 == &linebuf[LBSIZE+1]) {
+ (void) fprintf(stderr, "Output line too long.\n");
+ *--p1 = '\0';
+ }
+ } while(*p1++ = *p2++);
+ spend = p1-1;
+ break;
+
+ case HCOM:
+ p1 = holdsp;
+ p2 = linebuf;
+ while(*p1++ = *p2++);
+ hspend = p1-1;
+ break;
+
+ case CHCOM:
+ *hspend++ = '\n';
+ p1 = hspend;
+ p2 = linebuf;
+ do {
+ if (p1 == &holdsp[LBSIZE+1]) {
+ (void) fprintf(stderr, "Hold space overflowed.\n");
+ *--p1 = '\0';
+ }
+ } while(*p1++ = *p2++);
+ hspend = p1-1;
+ break;
+
+ case ICOM:
+ for(p1 = ipc->r1.re1; *p1; )
+ (void) putc(*p1++, stdout);
+ (void) putc('\n', stdout);
+ break;
+
+ case BCOM:
+ jflag = 1;
+ break;
+
+
+ case LCOM:
+ p1 = linebuf;
+ p2 = genbuf;
+ genbuf[72] = 0;
+ while(*p1)
+ if((unsigned char)*p1 >= 040) {
+ if(*p1 == 0177) {
+ p3 = rub;
+ while(*p2++ = *p3++)
+ if(p2 >= lcomend) {
+ *p2 = '\\';
+ (void) fprintf(stdout, "%s\n", genbuf);
+ p2 = genbuf;
+ }
+ p2--;
+ p1++;
+ continue;
+ }
+ if(!isprint(*p1 & 0377)) {
+ *p2++ = '\\';
+ if(p2 >= lcomend) {
+ *p2 = '\\';
+ (void) fprintf(stdout, "%s\n", genbuf);
+ p2 = genbuf;
+ }
+ *p2++ = (*p1 >> 6) + '0';
+ if(p2 >= lcomend) {
+ *p2 = '\\';
+ (void) fprintf(stdout, "%s\n", genbuf);
+ p2 = genbuf;
+ }
+ *p2++ = ((*p1 >> 3) & 07) + '0';
+ if(p2 >= lcomend) {
+ *p2 = '\\';
+ (void) fprintf(stdout, "%s\n", genbuf);
+ p2 = genbuf;
+ }
+ *p2++ = (*p1++ & 07) + '0';
+ if(p2 >= lcomend) {
+ *p2 = '\\';
+ (void) fprintf(stdout, "%s\n", genbuf);
+ p2 = genbuf;
+ }
+ } else {
+ *p2++ = *p1++;
+ if(p2 >= lcomend) {
+ *p2 = '\\';
+ (void) fprintf(stdout, "%s\n", genbuf);
+ p2 = genbuf;
+ }
+ }
+ } else {
+ p3 = trans[(unsigned char)*p1-1];
+ while(*p2++ = *p3++)
+ if(p2 >= lcomend) {
+ *p2 = '\\';
+ (void) fprintf(stdout, "%s\n", genbuf);
+ p2 = genbuf;
+ }
+ p2--;
+ p1++;
+ }
+ *p2 = 0;
+ (void) fprintf(stdout, "%s\n", genbuf);
+ break;
+
+ case NCOM:
+ if(!nflag) {
+ for(p1 = linebuf; p1 < spend; p1++)
+ (void) putc(*p1, stdout);
+ (void) putc('\n', stdout);
+ }
+
+ if(aptr > abuf)
+ arout();
+ if((execp = gline(linebuf)) == 0) {
+ pending = ipc;
+ delflag = 1;
+ break;
+ }
+ spend = execp;
+
+ break;
+ case CNCOM:
+ if(aptr > abuf)
+ arout();
+ *spend++ = '\n';
+ if((execp = gline(spend)) == 0) {
+ pending = ipc;
+ delflag = 1;
+ break;
+ }
+ spend = execp;
+ break;
+
+ case PCOM:
+ for(p1 = linebuf; p1 < spend; p1++)
+ (void) putc(*p1, stdout);
+ (void) putc('\n', stdout);
+ break;
+ case CPCOM:
+ cpcom:
+ for(p1 = linebuf; *p1 != '\n' && *p1 != '\0'; )
+ (void) putc(*p1++, stdout);
+ (void) putc('\n', stdout);
+ break;
+
+ case QCOM:
+ if(!nflag) {
+ for(p1 = linebuf; p1 < spend; p1++)
+ (void) putc(*p1, stdout);
+ (void) putc('\n', stdout);
+ }
+ if(aptr > abuf) arout();
+ (void) fclose(stdout);
+ exit(0);
+ case RCOM:
+ if(aptr >= &abuf[ABUFSIZE]) {
+ (void) fprintf(stderr, "Too many appends or reads after line %lld\n",
+ lnum);
+ } else {
+ *aptr++ = ipc;
+ *aptr = 0;
+ }
+ break;
+
+ case SCOM:
+ i = substitute(ipc);
+ if(ipc->r1.pfl && nflag && i)
+ if(ipc->r1.pfl == 1) {
+ for(p1 = linebuf; p1 < spend; p1++)
+ (void) putc(*p1, stdout);
+ (void) putc('\n', stdout);
+ }
+ else
+ goto cpcom;
+ if(i && ipc->r1.fcode)
+ goto wcom;
+ break;
+
+ case TCOM:
+ if(sflag == 0) break;
+ sflag = 0;
+ jflag = 1;
+ break;
+
+ wcom:
+ case WCOM:
+ (void) fprintf(ipc->r1.fcode, "%s\n", linebuf);
+ (void) fflush(ipc->r1.fcode);
+ break;
+ case XCOM:
+ p1 = linebuf;
+ p2 = genbuf;
+ while(*p2++ = *p1++);
+ p1 = holdsp;
+ p2 = linebuf;
+ while(*p2++ = *p1++);
+ spend = p2 - 1;
+ p1 = genbuf;
+ p2 = holdsp;
+ while(*p2++ = *p1++);
+ hspend = p2 - 1;
+ break;
+
+ case YCOM:
+ p1 = linebuf;
+ p2 = ipc->r1.re1;
+ while(*p1 = p2[(unsigned char)*p1]) p1++;
+ break;
+ }
+
+}
+
+char *gline(addr)
+char *addr;
+{
+ register char *p1, *p2;
+ register c;
+ sflag = 0;
+ p1 = addr;
+ p2 = cbp;
+ for (;;) {
+ if (p2 >= ebp) {
+ if(f < 0 || (c = read(f, ibuf, BUFSIZ)) == 0) {
+ return(0);
+ }
+ if(c < 0) {
+ (void) fprintf(stderr, "sed: error reading ");
+ perror(ifname);
+ exit(2);
+ }
+ p2 = ibuf;
+ ebp = ibuf+c;
+ }
+ if ((c = *p2++) == '\n') {
+ if(p2 >= ebp) {
+ if(f < 0 || (c = read(f, ibuf, BUFSIZ)) == 0) {
+ if(f >= 0) {
+ (void) close(f);
+ f = -1;
+ }
+ if(eargc == 0)
+ dolflag = 1;
+ }
+ if(c < 0) {
+ (void) fprintf(stderr, "sed: error reading ");
+ perror(ifname);
+ exit(2);
+ }
+
+ p2 = ibuf;
+ ebp = ibuf + c;
+ }
+ break;
+ }
+ if(c)
+ if(p1 < &linebuf[LBSIZE])
+ *p1++ = c;
+ }
+ lnum++;
+ *p1 = 0;
+ cbp = p2;
+
+ return(p1);
+}
+
+char *comple(x1, ep, x3, x4)
+char *x1, *x3;
+char x4;
+register char *ep;
+{
+ register char *p;
+
+ p = compile(x1, ep + 1, x3, x4);
+ if(p == ep + 1)
+ return(ep);
+ *ep = circf;
+ return(p);
+}
+
+regerr(err)
+register err;
+{
+ switch(err) {
+
+ case 11:
+ comperr("Range endpoint too large: %s");
+ break;
+
+ case 16:
+ comperr("Bad number: %s");
+ break;
+
+ case 25:
+ comperr("``\\digit'' out of range: %s");
+ break;
+
+ case 36:
+ comperr("Illegal or missing delimiter: %s");
+ break;
+
+ case 41:
+ comperr("No remembered search string: %s");
+ break;
+
+ case 42:
+ comperr("\\( \\) imbalance: %s");
+ break;
+
+ case 43:
+ comperr("Too many \\(: %s");
+ break;
+
+ case 44:
+ comperr("More than 2 numbers given in \\{ \\}: %s");
+ break;
+
+ case 45:
+ comperr("} expected after \\: %s");
+ break;
+
+ case 46:
+ comperr("First number exceeds second in \\{ \\}: %s");
+ break;
+
+ case 49:
+ comperr("[ ] imbalance: %s");
+ break;
+
+ case 50:
+ comperr(TMMES);
+ break;
+
+ default:
+ (void) fprintf(stderr, "Unknown regexp error code %d: %s\n",
+ err, linebuf);
+ exit(2);
+ break;
+ }
+}
+
+arout()
+{
+ register char *p1;
+ FILE *fi;
+ char c;
+ int t;
+
+ aptr = abuf - 1;
+ while(*++aptr) {
+ if((*aptr)->r1.command == ACOM) {
+ for(p1 = (*aptr)->r1.re1; *p1; )
+ (void) putc(*p1++, stdout);
+ (void) putc('\n', stdout);
+ } else {
+ if((fi = fopen((*aptr)->r1.re1, "r")) == NULL)
+ continue;
+ while((t = getc(fi)) != EOF) {
+ c = t;
+ (void) putc(c, stdout);
+ }
+ (void) fclose(fi);
+ }
+ }
+ aptr = abuf;
+ *aptr = 0;
+}
+
diff --git a/usr/src/ucbcmd/shutdown/Makefile b/usr/src/ucbcmd/shutdown/Makefile
new file mode 100644
index 0000000000..6d2efc86c9
--- /dev/null
+++ b/usr/src/ucbcmd/shutdown/Makefile
@@ -0,0 +1,62 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 1995, 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+PROG= shutdown
+
+PROGSRC= shutdown.c
+PROGOBJS= shutdown.o
+
+include ../Makefile.ucbcmd
+
+INC1 = $(ROOT)/usr/ucbinclude
+
+FILEMODE= 755
+
+LDLIBS += -lsocket -lrpcsvc -lnsl -L$(ROOT)/usr/ucblib -lucb -lbsm
+
+#CPPFLAGS.master += -I$(INC1)
+CPPFLAGS = -I$(INC1) $(CPPFLAGS.master)
+
+XGETFLAGS += -a -x shutdown.xcl
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(PROGOBJS)
+ $(SETRUNPATH) $(LINK.c) $(PROGOBJS) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG)
+
+clean:
+ $(RM) $(PROGOBJS)
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/shutdown/shutdown.c b/usr/src/ucbcmd/shutdown/shutdown.c
new file mode 100644
index 0000000000..b1e19f9acc
--- /dev/null
+++ b/usr/src/ucbcmd/shutdown/shutdown.c
@@ -0,0 +1,745 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <ctype.h>
+#include <setjmp.h>
+#include <utmpx.h>
+#include <pwd.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <rpcsvc/mount.h>
+#include <rpcsvc/rwall.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <locale.h>
+#include <sys/syslog.h>
+#include <zone.h>
+#include <signal.h>
+
+/*
+ * /usr/etc/shutdown when [messages]
+ *
+ * allow super users to tell users and remind users
+ * of iminent shutdown of unix
+ * and shut it down automatically
+ * and even reboot or halt the machine if they desire
+ */
+
+#define EPATH "PATH=/usr/ucb:/usr/bin:/usr/sbin:"
+#define REBOOT "/usr/sbin/reboot"
+#define HALT "/usr/sbin/halt"
+#define MAXINTS 20
+#define HOURS *3600
+#define MINUTES *60
+#define SECONDS
+#define NLOG 600 /* no of bytes possible for message */
+#define NOLOGTIME 5 MINUTES
+#define IGNOREUSER "sleeper"
+
+struct hostlist {
+ char *host;
+ struct hostlist *nxt;
+} *hostlist;
+
+char hostname[MAXHOSTNAMELEN];
+char mbuf[BUFSIZ];
+
+void timeout();
+time_t getsdt();
+
+extern char *malloc();
+
+extern char *ctime();
+extern struct tm *localtime();
+
+extern char *strcpy();
+extern char *strncat();
+extern off_t lseek();
+
+struct utmpx *utmpx;
+
+int sint;
+int stogo;
+char tpath[] = "/dev/";
+int nlflag = 1; /* nolog yet to be done */
+int killflg = 1;
+int doreboot = 0;
+int halt = 0;
+int fast = 0;
+char *nosync = NULL;
+char nosyncflag[] = "-n";
+char term[sizeof tpath + sizeof (utmpx->ut_line)];
+char tbuf[BUFSIZ];
+char nolog1[] = "\n\nNO LOGINS: System going down at %5.5s\n\n";
+char mesg[NLOG+1];
+#ifdef DEBUG
+char fastboot[] = "fastboot";
+#else
+char fastboot[] = "/fastboot";
+#endif
+char nologin[] = "/etc/nologin";
+time_t nowtime;
+jmp_buf alarmbuf;
+
+struct interval {
+ int stogo;
+ int sint;
+} interval[] = {
+ 4 HOURS, 1 HOURS,
+ 2 HOURS, 30 MINUTES,
+ 1 HOURS, 15 MINUTES,
+ 30 MINUTES, 10 MINUTES,
+ 15 MINUTES, 5 MINUTES,
+ 10 MINUTES, 5 MINUTES,
+ 5 MINUTES, 3 MINUTES,
+ 2 MINUTES, 1 MINUTES,
+ 1 MINUTES, 30 SECONDS,
+ 0 SECONDS, 0 SECONDS
+};
+
+char *msg1 = "shutdown: '%c' - unknown flag\n";
+char *msg2 = "Usage: shutdown [ -krhfn ] shutdowntime [ message ]\n";
+char *msg3 = "Usage: shutdown [ -krhfn ] shutdowntime [ message ]";
+char *msg4 = "Usage: shutdown [ -krhfn ] shutdowntime [ message ]\n";
+char *msg5 = "Usage: shutdown [ -krhfn ] shutdowntime [ message ]";
+char *msg6 = "\n\007\007System shutdown time has arrived\007\007\n";
+char *msg7 = "but you'll have to do it yourself\n";
+char *msg8 = "but you'll have to do it yourself";
+char *msg9 = "-l (without fsck's)\n";
+char *msg10 = "-l %s\n";
+char *msg11 = " (without fsck's)\n";
+char *msg12 = "That must be tomorrow\nCan't you wait till then?\n";
+char *msg13 = "That must be tomorrow";
+char *msg14 = "Can't you wait till then?";
+char *msg15 = "\007\007\t*** %sSystem shutdown message from %s@%s ***\r\n\n";
+char *msg16 = "System going down at %5.5s\r\n";
+char *msg17 = "System going down in %d minute%s\r\n";
+char *msg18 = "System going down in %d second%s\r\n";
+char *msg19 = "System going down IMMEDIATELY\r\n";
+char *msg20 = "Can't get PID for init\n";
+
+char *shutter, *getlogin();
+
+
+pid_t
+get_initpid()
+{
+ pid_t init_pid;
+
+ if (zone_getattr(getzoneid(), ZONE_ATTR_INITPID, &init_pid,
+ sizeof (init_pid)) != sizeof (init_pid)) {
+ (void) fprintf(stderr, gettext(msg20));
+ exit(1);
+ }
+ return (init_pid);
+}
+
+int
+main(int argc, char **argv)
+{
+ int i;
+ char *f;
+ char *ts;
+ time_t sdt;
+ int h, m;
+ int first;
+ void finish_sig();
+ FILE *termf;
+ struct passwd *pw, *getpwuid();
+ extern char *strcat();
+ extern uid_t geteuid();
+ struct hostlist *hl;
+ char *shutdown_program;
+ char *shutdown_action;
+ int fd;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ audit_shutdown_setup(argc, argv);
+
+ shutter = getlogin();
+ if (shutter == 0 && (pw = getpwuid(getuid())))
+ shutter = pw->pw_name;
+ if (shutter == 0)
+ shutter = "???";
+ (void) gethostname(hostname, sizeof (hostname));
+ openlog("shutdown", 0, LOG_AUTH);
+ argc--, argv++;
+ while (argc > 0 && (f = argv[0], *f++ == '-')) {
+ while (i = *f++) {
+ switch (i) {
+ case 'k':
+ killflg = 0;
+ continue;
+ case 'n':
+ nosync = nosyncflag;
+ continue;
+ case 'f':
+ fast = 1;
+ continue;
+ case 'r':
+ doreboot = 1;
+ continue;
+ case 'h':
+ halt = 1;
+ continue;
+ default:
+ (void) fprintf(stderr, gettext(msg1),
+ i);
+ (void) fprintf(stderr, gettext(msg2));
+ finish(gettext(msg3), "", 1);
+ }
+ }
+ argc--, argv++;
+ }
+ if (argc < 1) {
+ (void) fprintf(stderr, gettext(msg4));
+ finish(gettext(msg5), "", 1);
+ }
+ if (doreboot && halt) {
+ (void) fprintf(stderr,
+ gettext("shutdown: Incompatible switches '-r' & '-h'\n"));
+ finish(gettext("shutdown: Incompatible switches '-r' & '-h'"),
+ "", 1);
+ }
+ if (fast && (nosync == nosyncflag)) {
+ (void) fprintf(stderr,
+ gettext("shutdown: Incompatible switches '-f' & '-n'\n"));
+ finish(gettext("shutdown: Incompatible switches '-f' & '-n'"),
+ "", 1);
+ }
+ if (geteuid()) {
+ (void) fprintf(stderr, gettext("shutdown: NOT super-user\n"));
+ finish(gettext("shutdown: NOT super-user"), "", 1);
+ }
+ gethostlist();
+ nowtime = time((time_t *)NULL);
+ sdt = getsdt(argv[0]);
+ argc--, argv++;
+ mesg[0] = '\0';
+ i = 0;
+ while (argc-- > 0) {
+ if (i + strlen(*argv) > NLOG)
+ break; /* no more room for the message */
+ i += strlen(*argv) + 1;
+ (void) strcat(mesg, *argv++);
+ (void) strcat(mesg, " ");
+ }
+ if (i != 0)
+ mesg[i - 1] = '\0'; /* remove trailing blank */
+ m = ((stogo = sdt - nowtime) + 30)/60;
+ h = m/60;
+ m %= 60;
+ ts = ctime(&sdt);
+ (void) printf(gettext("Shutdown at %5.5s (in "), ts+11);
+ if (h > 0)
+ (void) printf("%d hour%s ", h, h != 1 ? "s" : "");
+ (void) printf("%d minute%s) ", m, m != 1 ? "s" : "");
+#ifndef DEBUG
+ (void) signal(SIGHUP, SIG_IGN);
+ (void) signal(SIGQUIT, SIG_IGN);
+ (void) signal(SIGINT, SIG_IGN);
+#endif
+ (void) signal(SIGTTOU, SIG_IGN);
+ (void) signal(SIGINT, finish_sig);
+ (void) signal(SIGALRM, timeout);
+ (void) setpriority(PRIO_PROCESS, 0, PRIO_MIN);
+ (void) fflush(stdout);
+#ifndef DEBUG
+ if (i = fork()) {
+ (void) printf(gettext("[pid %d]\n"), i);
+ exit(0);
+ }
+#else
+ (void) putc('\n', stdout);
+#endif
+ sint = 1 HOURS;
+ f = "";
+ first = 1;
+ if (doreboot) {
+ shutdown_program = REBOOT;
+ shutdown_action = "reboot";
+ } else if (halt) {
+ shutdown_program = HALT;
+ shutdown_action = "halt";
+ } else {
+ shutdown_program = NULL;
+ shutdown_action = "shutdown";
+ }
+ for (;;) {
+ for (i = 0; stogo <= interval[i].stogo && interval[i].sint; i++)
+ sint = interval[i].sint;
+ if (stogo > 0 && (stogo-sint) < interval[i].stogo)
+ sint = stogo - interval[i].stogo;
+ if (stogo <= NOLOGTIME && nlflag) {
+ nlflag = 0;
+ nolog(sdt);
+ }
+ if (sint >= stogo || sint == 0)
+ f = "FINAL ";
+ nowtime = time((time_t *)NULL);
+
+ setutxent();
+
+ while ((utmpx = getutxent()) != NULL) {
+ if (utmpx->ut_name[0] &&
+ strncmp(utmpx->ut_name, IGNOREUSER,
+ sizeof (utmpx->ut_name))) {
+ /*
+ * don't write to pty's unless they're rlogin sessions
+ */
+ if (utmpx->ut_type != USER_PROCESS &&
+ utmpx->ut_user[0] != '\0')
+ continue;
+
+ if (setjmp(alarmbuf))
+ continue;
+ (void) strcpy(term, tpath);
+ (void) strncat(term, utmpx->ut_line,
+ sizeof (utmpx->ut_line));
+ (void) alarm(5);
+
+ /* check if device is really a tty */
+ if ((fd = open(term, O_WRONLY|O_NOCTTY)) == -1) {
+ fprintf(stderr, gettext("Cannot open %s.\n"),
+ term);
+ (void) alarm(0);
+ continue;
+ } else {
+ if (!isatty(fd)) {
+ fprintf(stderr,
+ gettext("%.*s in utmpx is not a tty\n"),
+ sizeof (utmpx->ut_line), utmpx->ut_line);
+ syslog(LOG_CRIT, "%.*s in utmpx is not "
+ "a tty\n", sizeof (utmpx->ut_line),
+ utmpx->ut_line);
+ close(fd);
+ (void) alarm(0);
+ continue;
+ }
+ }
+ close(fd);
+#ifdef DEBUG
+ if ((termf = stdout) != NULL)
+#else
+ if ((termf = fopen(term, "w")) != NULL)
+#endif
+ {
+ (void) alarm(0);
+ setbuf(termf, tbuf);
+ (void) fprintf(termf, "\n\r\n");
+ warn(termf, sdt, nowtime, f, first);
+ (void) alarm(5);
+#ifdef DEBUG
+ (void) fflush(termf);
+#else
+ (void) fclose(termf);
+#endif
+ (void) alarm(0);
+ }
+ }
+ } /* while */
+
+ endutxent();
+
+ for (hl = hostlist; hl != NULL; hl = hl->nxt)
+ rwarn(hl->host, sdt, nowtime, f, first);
+ if (stogo <= 0) {
+ (void) printf(gettext(msg6));
+ if (*mesg)
+ syslog(LOG_CRIT, "%s by %s: %s",
+ shutdown_action, shutter, mesg);
+ else
+ syslog(LOG_CRIT, "%s by %s",
+ shutdown_action, shutter);
+ sleep(2);
+ (void) unlink(nologin);
+ if (!killflg) {
+ (void) printf(gettext(msg7));
+ finish(gettext(msg8), "", 0);
+ }
+ if (fast)
+ doitfast();
+#ifndef DEBUG
+ (void) putenv(EPATH);
+ if (shutdown_program != NULL) {
+ audit_shutdown_success();
+ execlp(shutdown_program, shutdown_program,
+ "-l", nosync, (char *)0);
+ } else {
+ if (geteuid() == 0) {
+ audit_shutdown_success();
+ sleep(5);
+ }
+ if (getzoneid() == GLOBAL_ZONEID) {
+ (void) system(
+ "/sbin/bootadm -a update_all");
+ }
+
+ (void) kill(get_initpid(), SIGINT); /* sync */
+ (void) kill(get_initpid(), SIGINT); /* sync */
+ sleep(20);
+ }
+#else
+ if (shutdown_program) {
+ (void) printf("%s ", shutdown_program);
+ if (fast)
+ (void) printf(gettext(msg9));
+ else if (nosync != NULL)
+ (void) printf(gettext(msg10), nosync);
+ else
+ (void) printf(gettext("-l\n"));
+ } else {
+ (void) printf("/sbin/bootadm -a update_all");
+ (void) printf("kill -INT 1");
+ if (fast)
+ (void) printf(gettext(msg11));
+ else
+ (void) printf("\n");
+ }
+#endif
+ finish("", "", 0);
+ }
+ stogo = sdt - time((time_t *)NULL);
+ if (stogo > 0 && sint > 0)
+ sleep((unsigned)(sint < stogo ? sint : stogo));
+ stogo -= sint;
+ first = 0;
+ }
+ /* NOTREACHED */
+}
+
+time_t
+getsdt(s)
+ char *s;
+{
+ time_t t, t1, tim;
+ char c;
+ struct tm *lt;
+ int c_count;
+
+ if (strcmp(s, "now") == 0)
+ return (nowtime);
+ if (*s == '+') {
+ ++s;
+ t = 0;
+ for (c_count = 1; ; c_count++) {
+ c = *s++;
+ if (!isdigit(c)) {
+ if (c_count == 1) {
+ goto badform;
+ } else {
+ break;
+ }
+ }
+ t = t * 10 + c - '0';
+ }
+ if (t <= 0)
+ t = 5;
+ t *= 60;
+ tim = time((time_t *)NULL) + t;
+ return (tim);
+ }
+ t = 0;
+ while (strlen(s) > 2 && isdigit(*s))
+ t = t * 10 + *s++ - '0';
+ if (*s == ':')
+ s++;
+ if (t > 23)
+ goto badform;
+ tim = t*60;
+ t = 0;
+ while (isdigit(*s))
+ t = t * 10 + *s++ - '0';
+ if (t > 59)
+ goto badform;
+ tim += t;
+ tim *= 60;
+ t1 = time((time_t *)NULL);
+ lt = localtime(&t1);
+ t = lt->tm_sec + lt->tm_min*60 + lt->tm_hour*3600;
+ if (tim < t || tim >= (24*3600)) {
+ /* before now or after midnight */
+ (void) printf(gettext(msg12));
+ finish(gettext(msg13), gettext(msg14), 0);
+ }
+ return (t1 + tim - t);
+badform:
+ (void) printf(gettext("Bad time format\n"));
+ finish(gettext("Bad time format"), "", 0);
+ /*NOTREACHED*/
+}
+
+warn(termf, sdt, now, type, first)
+ FILE *termf;
+ time_t sdt, now;
+ char *type;
+ int first;
+{
+ char *ts;
+ time_t delay = sdt - now;
+
+ if (delay > 8)
+ while (delay % 5)
+ delay++;
+
+ (void) fprintf(termf, gettext(msg15), type, shutter, hostname);
+
+ ts = ctime(&sdt);
+ if (delay > 10 MINUTES)
+ (void) fprintf(termf, gettext(msg16), ts+11);
+ else if (delay > 95 SECONDS) {
+ (void) fprintf(termf, gettext(msg17), (delay+30)/60,
+ (delay+30)/60 != 1 ? "s" : "");
+ } else if (delay > 0) {
+ (void) fprintf(termf, gettext(msg18), delay,
+ delay != 1 ? "s" : "");
+ } else
+ (void) fprintf(termf, gettext(msg19));
+
+ if (first || sdt - now > 1 MINUTES) {
+ if (*mesg)
+ (void) fprintf(termf, "\t...%s\r\n", mesg);
+ }
+}
+
+doitfast()
+{
+ FILE *fastd;
+
+ if ((fastd = fopen(fastboot, "w")) != NULL) {
+ (void) putc('\n', fastd);
+ (void) fclose(fastd);
+ }
+}
+
+rwarn(host, sdt, now, type, first)
+ char *host;
+ time_t sdt, now;
+ char *type;
+ int first;
+{
+ char *ts;
+ time_t delay = sdt - now;
+ char *bufp;
+
+ if (delay > 8)
+ while (delay % 5)
+ delay++;
+
+ (void) sprintf(mbuf,
+ "\007\007\t*** %sShutdown message for %s from %s@%s ***\r\n\n",
+ type, hostname, shutter, hostname);
+ ts = ctime(&sdt);
+ bufp = mbuf + strlen(mbuf);
+ if (delay > 10 MINUTES) {
+ (void) sprintf(bufp, "%s going down at %5.5s\r\n", hostname,
+ ts+11);
+ } else if (delay > 95 SECONDS) {
+ (void) sprintf(bufp, "%s going down in %d minute%s\r\n",
+ hostname, (delay+30)/60, (delay+30)/60 != 1 ? "s" : "");
+ } else if (delay > 0) {
+ (void) sprintf(bufp, "%s going down in %d second%s\r\n",
+ hostname, delay, delay != 1 ? "s" : "");
+ } else {
+ (void) sprintf(bufp, "%s going down IMMEDIATELY\r\n",
+ hostname);
+ }
+ bufp = mbuf + strlen(mbuf);
+ if (first || sdt - now > 1 MINUTES) {
+ if (*mesg)
+ (void) sprintf(bufp, "\t...%s\r\n", mesg);
+ }
+ rprintf(host, mbuf);
+}
+
+rprintf(host, bufp)
+ char *host, *bufp;
+{
+ int err;
+
+#ifdef DEBUG
+ (void) fprintf(stderr, gettext("about to call %s\n"), host);
+#endif
+ if (err = callrpcfast(host, (rpcprog_t)WALLPROG, (rpcvers_t)WALLVERS,
+ (rpcproc_t)WALLPROC_WALL, xdr_dirpath, (char *)&bufp, xdr_void,
+ (char *)NULL)) {
+#ifdef DEBUG
+ (void) fprintf(stderr, gettext("couldn't make rpc call: "));
+ clnt_perrno(err);
+ (void) fprintf(stderr, "\n");
+#endif
+ }
+}
+
+nolog(sdt)
+ time_t sdt;
+{
+ FILE *nologf;
+
+ (void) unlink(nologin); /* in case linked to std file */
+ if ((nologf = fopen(nologin, "w")) != NULL) {
+ (void) fprintf(nologf, nolog1, (ctime(&sdt)) + 11);
+ if (*mesg)
+ (void) fprintf(nologf, "\t%s\n", mesg);
+ (void) fclose(nologf);
+ }
+}
+
+void
+finish_sig()
+{
+ finish("SIGINT", "", 1);
+}
+
+finish(s1, s2, exitcode)
+ char *s1;
+ char *s2;
+{
+ (void) signal(SIGINT, SIG_IGN);
+ exit(exitcode);
+}
+
+void
+timeout()
+{
+ (void) signal(SIGALRM, (void(*)())timeout);
+ longjmp(alarmbuf, 1);
+}
+
+gethostlist()
+{
+ int s;
+ struct mountbody *ml;
+ struct hostlist *hl;
+ struct sockaddr_in addr;
+ CLIENT *cl;
+ static struct timeval TIMEOUT = { 25, 0 };
+
+ /*
+ * check for portmapper
+ */
+ get_myaddress(&addr);
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ return;
+ if (connect(s, (struct sockaddr *)&addr, sizeof (addr)) < 0)
+ return;
+ (void) close(s);
+
+ /*
+ * First try tcp, then drop back to udp if
+ * tcp is unavailable (an old version of mountd perhaps)
+ * Using tcp is preferred because it can handle
+ * arbitrarily long export lists.
+ */
+ cl = clnt_create(hostname, (ulong_t)MOUNTPROG, (ulong_t)MOUNTVERS,
+ "tcp");
+ if (cl == NULL) {
+ cl = clnt_create(hostname, (ulong_t)MOUNTPROG,
+ (ulong_t)MOUNTVERS, "udp");
+ if (cl == NULL) {
+ if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED) {
+ clnt_pcreateerror("shutdown warning");
+ }
+ return;
+ }
+ }
+
+ ml = NULL;
+ if (clnt_call(cl, MOUNTPROC_DUMP,
+ xdr_void, 0, xdr_mountlist, (char *)&ml, TIMEOUT) != RPC_SUCCESS) {
+ clnt_perror(cl, "shutdown warning");
+ return;
+ }
+ for (; ml != NULL; ml = ml->ml_next) {
+ for (hl = hostlist; hl != NULL; hl = hl->nxt)
+ if (strcmp(ml->ml_hostname, hl->host) == 0)
+ goto again;
+ hl = (struct hostlist *)malloc(sizeof (struct hostlist));
+ hl->host = ml->ml_hostname;
+ hl->nxt = hostlist;
+ hostlist = hl;
+ again:;
+ }
+}
+
+/*
+ * Don't want to wait for usual portmapper timeout you get with
+ * callrpc or clnt_call, so use rmtcall instead. Use timeout
+ * of 8 secs, based on the per try timeout of 3 secs for rmtcall
+ */
+callrpcfast(host, prognum, versnum, procnum, inproc, in, outproc, out)
+ char *host;
+ rpcprog_t prognum;
+ rpcvers_t versnum;
+ rpcproc_t procnum;
+ xdrproc_t inproc, outproc;
+ char *in, *out;
+{
+ struct sockaddr_in server_addr;
+ struct hostent *hp;
+ struct timeval rpctimeout;
+ rpcport_t port;
+
+ if ((hp = gethostbyname(host)) == NULL)
+ return ((int)RPC_UNKNOWNHOST);
+ bcopy(hp->h_addr, (char *)&server_addr.sin_addr, hp->h_length);
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = 0;
+ rpctimeout.tv_sec = 8;
+ rpctimeout.tv_usec = 0;
+ return ((int)pmap_rmtcall(&server_addr, prognum, versnum, procnum,
+ inproc, in, outproc, out, rpctimeout, &port));
+}
diff --git a/usr/src/ucbcmd/shutdown/shutdown.xcl b/usr/src/ucbcmd/shutdown/shutdown.xcl
new file mode 100644
index 0000000000..afd306ad0d
--- /dev/null
+++ b/usr/src/ucbcmd/shutdown/shutdown.xcl
@@ -0,0 +1,43 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+msgid "/dev/"
+msgid "-n"
+msgid "/fastboot"
+msgid "/etc/nologin"
+msgid "-l %s\n"
+msgid ""
+msgid "???"
+msgid " "
+msgid "s"
+msgid "/etc/utmp"
+msgid "w"
+msgid "\n\r\n"
+msgid "%s by %s: %s"
+msgid "%s by %s"
+msgid "-l"
+msgid "%s "
+msgid "-l\n"
+msgid "kill -INT 1"
+msgid "\n"
+msgid "\t...%s\r\n"
+msgid "\t%s\n"
+msgid "SIGINT"
diff --git a/usr/src/ucbcmd/stty/Makefile b/usr/src/ucbcmd/stty/Makefile
new file mode 100644
index 0000000000..9cb7427e2c
--- /dev/null
+++ b/usr/src/ucbcmd/stty/Makefile
@@ -0,0 +1,50 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= stty
+
+PROGSRC= stty.c sttyparse.c sttytable.c
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(PROGSRC)
+ $(LINK.c) $(PROGSRC) -o $@ $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/stty/stty.c b/usr/src/ucbcmd/stty/stty.c
new file mode 100644
index 0000000000..712079f5fc
--- /dev/null
+++ b/usr/src/ucbcmd/stty/stty.c
@@ -0,0 +1,731 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1995 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+
+#include <stdio.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <termio.h>
+#include <sys/stermio.h>
+#include <sys/termiox.h>
+#include "stty.h"
+
+extern char *getenv();
+extern void exit();
+extern void perror();
+
+static char *STTY="stty: ";
+static char *USAGE="usage: stty [-agh] [modes]\n";
+static int pitt = 0;
+static struct termios cb;
+static struct termio ocb; /* for non-streams devices */
+static struct stio stio;
+static struct termiox termiox;
+static struct winsize winsize, owinsize;
+static int term;
+
+#define ioctl_desc 1
+#define output stderr
+
+main(argc, argv)
+char *argv[];
+{
+
+ int i;
+ char *s_arg, *sttyparse(); /* s_arg: ptr to mode to be set */
+ extern const struct speeds speeds[];
+
+ if (argc == 2) {
+ /*
+ * "stty size", "stty speed" and "stty -g" are intended for
+ * use within backquotes; thus, they do the "fetch" "ioctl"
+ * from "/dev/tty" and always print their result on the
+ * standard output.
+ * Since their standard output is likely to be a pipe, they
+ * should not try to read the modes from the standard output.
+ */
+ if (strcmp(argv[1], "size") == 0) {
+ if ((i = open("/dev/tty", 0)) < 0) {
+ perror("stty: Cannot open /dev/tty");
+ exit(2);
+ }
+ if (ioctl(i, TIOCGWINSZ, &winsize) < 0) {
+ perror("stty: TIOCGWINSZ");
+ exit(2);
+ }
+ (void) printf("%d %d\n",winsize.ws_row,winsize.ws_col);
+ exit(0);
+ }
+ else if (strcmp(argv[1], "speed") == 0) {
+ if ((i = open("/dev/tty", 0)) < 0) {
+ perror("stty: Cannot open /dev/tty");
+ exit(2);
+ }
+ if((term = get_ttymode(i, &ocb, &cb, &stio, &termiox,
+ &winsize)) < 0) {
+ perror(STTY);
+ exit(2);
+ }
+ if (term & TERMIOS) {
+ for(i=0; speeds[i].string; i++)
+ if (cfgetospeed(&cb) == speeds[i].speed) {
+ (void) printf("%s\n", speeds[i].string);
+ exit(0);
+ }
+ } else {
+ for(i=0; speeds[i].string; i++)
+ if ((cb.c_cflag&CBAUD) == speeds[i].speed) {
+ (void) printf("%s\n", speeds[i].string);
+ exit(0);
+ }
+ }
+ (void) printf("unknown\n");
+ exit(1);
+ }
+ else if (strcmp(argv[1], "-g") == 0) {
+ if ((i = open("/dev/tty", 0)) < 0) {
+ perror("stty: Cannot open /dev/tty");
+ exit(2);
+ }
+ if((term = get_ttymode(i, &ocb, &cb, &stio, &termiox,
+ &winsize)) < 0) {
+ perror(STTY);
+ exit(2);
+ }
+ prencode();
+ exit(0);
+ }
+ }
+
+ if((term = get_ttymode(ioctl_desc, &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
+ perror(STTY);
+ exit(2);
+ }
+ owinsize = winsize;
+ if (argc == 1) {
+ prmodes(0);
+ exit(0);
+ }
+ if ((argc ==2) && strcmp(argv[1], "all") ==0) {
+ prmodes(1);
+ exit(0);
+ }
+ if ((argc ==2) && strcmp(argv[1], "everything") ==0) {
+ pramodes(1);
+ exit(0);
+ }
+ if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0'))
+ switch(argv[1][1]) {
+ case 'a':
+ pramodes(0);
+ exit(0);
+ case 'h':
+ pramodes(1);
+ exit(0);
+ default:
+ (void) fprintf(stderr, "%s", USAGE);
+ exit(2);
+ }
+ if (s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize)) {
+ (void) fprintf(stderr, "unknown mode: %s\n", s_arg);
+ exit(2);
+ }
+
+ if(set_ttymode(ioctl_desc, term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize) == -1) {
+ perror(STTY);
+ exit(2);
+ }
+ exit(0); /*NOTREACHED*/
+}
+
+prmodes(moremodes) /* print modes, no options, argc is 1 */
+int moremodes;
+{
+ register m;
+
+ if (!(term & ASYNC)) {
+ m = stio.imode;
+ if (m & IUCLC) (void) fprintf(output, "iuclc ");
+ else (void) fprintf(output, "-iuclc ");
+ m = stio.omode;
+ if (m & OLCUC) (void) fprintf(output, "olcuc ");
+ else (void) fprintf(output, "-olcuc ");
+ if (m & TAB3) (void) fprintf(output, "tab3 ");
+ m = stio.lmode;
+ if (m & XCASE) (void) fprintf(output, "xcase ");
+ else (void) fprintf(output, "-xcase ");
+ if (m & STFLUSH) (void) fprintf(output, "stflush ");
+ else (void) fprintf(output, "-stflush ");
+ if (m & STWRAP) (void)fprintf(output, "stwrap ");
+ else (void) fprintf(output, "-stwrap ");
+ if (m & STAPPL) (void) fprintf(output, "stappl ");
+ else (void) fprintf(output, "-stappl ");
+ (void) fprintf(output, "\n");
+ }
+ if (term & ASYNC) {
+ m = cb.c_cflag;
+ if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
+ cfgetispeed(&cb) != cfgetospeed(&cb)) {
+ prspeed("ispeed ", cfgetispeed(&cb));
+ prspeed("ospeed ", cfgetospeed(&cb));
+ } else
+ prspeed("speed ", cfgetospeed(&cb));
+ if (m&PARENB) {
+ if((m&PAREXT) && (term & TERMIOS)) {
+ if (m&PARODD)
+ (void) fprintf(output,"markp ");
+ else
+ (void) fprintf(output,"spacep ");
+ } else {
+ if (m&PARODD)
+ (void) fprintf(output,"oddp ");
+ else
+ (void) fprintf(output,"evenp ");
+ }
+ } else
+ (void) fprintf(output,"-parity ");
+ if(((m&PARENB) && !(m&CS7)) || (!(m&PARENB) && !(m&CS8)))
+ (void) fprintf(output,"cs%c ",'5'+(m&CSIZE)/CS6);
+ if (m&CSTOPB)
+ (void) fprintf(output,"cstopb ");
+ if (m&HUPCL)
+ (void) fprintf(output,"hupcl ");
+ if (!(m&CREAD))
+ (void) fprintf(output,"-cread ");
+ if (m&CLOCAL)
+ (void) fprintf(output,"clocal ");
+ if (m&LOBLK)
+ (void) fprintf(output,"loblk ");
+ (void) fprintf(output,"\n");
+ if(ocb.c_line != 0)
+ (void) fprintf(output,"line = %d; ", ocb.c_line);
+ if(term & WINDOW) {
+ (void)fprintf(output,"rows = %d; columns = %d;", winsize.ws_row, winsize.ws_col);
+ (void)fprintf(output," ypixels = %d; xpixels = %d;\n", winsize.ws_ypixel, winsize.ws_xpixel);
+ }
+ if((cb.c_lflag&ICANON)== 0)
+ (void) fprintf(output,"min = %d; time = %d;\n",
+ cb.c_cc[VMIN], cb.c_cc[VTIME]);
+ if (!moremodes) {
+ if(cb.c_cc[VINTR] != CINTR)
+ pit(cb.c_cc[VINTR], "intr", "; ");
+ if(cb.c_cc[VQUIT] != CQUIT)
+ pit(cb.c_cc[VQUIT], "quit", "; ");
+ if(cb.c_cc[VERASE] != CERASE)
+ pit(cb.c_cc[VERASE], "erase", "; ");
+ if(cb.c_cc[VKILL] != CKILL)
+ pit(cb.c_cc[VKILL], "kill", "; ");
+ if(cb.c_cc[VEOF] != CEOF)
+ pit(cb.c_cc[VEOF], "eof", "; ");
+ if(cb.c_cc[VEOL] != CNUL)
+ pit(cb.c_cc[VEOL], "eol", "; ");
+ if(cb.c_cc[VEOL2] != CNUL)
+ pit(cb.c_cc[VEOL2], "eol2", "; ");
+ if(cb.c_cc[VSWTCH] != CSWTCH)
+ pit(cb.c_cc[VSWTCH], "swtch", "; ");
+ if(term & TERMIOS) {
+ if(cb.c_cc[VSTART] != CSTART)
+ pit(cb.c_cc[VSTART], "start", "; ");
+ if(cb.c_cc[VSTOP] != CSTOP)
+ pit(cb.c_cc[VSTOP], "stop", "; ");
+ if(cb.c_cc[VSUSP] != CSUSP)
+ pit(cb.c_cc[VSUSP], "susp", "; ");
+ if(cb.c_cc[VDSUSP] != CDSUSP)
+ pit(cb.c_cc[VDSUSP], "dsusp", "; ");
+ if(cb.c_cc[VREPRINT] != CRPRNT)
+ pit(cb.c_cc[VREPRINT], "rprnt", "; ");
+ if(cb.c_cc[VDISCARD] != CFLUSH)
+ pit(cb.c_cc[VDISCARD], "flush", "; ");
+ if(cb.c_cc[VWERASE] != CWERASE)
+ pit(cb.c_cc[VWERASE], "werase", "; ");
+ if(cb.c_cc[VLNEXT] != CLNEXT)
+ pit(cb.c_cc[VLNEXT], "lnext", "; ");
+ }
+ }
+ if(pitt) (void) fprintf(output,"\n");
+ m = cb.c_iflag;
+ if (m&IGNBRK)
+ (void) fprintf(output,"ignbrk ");
+ else if (!(m&BRKINT))
+ (void) fprintf(output,"-brkint ");
+ if (!(m&INPCK))
+ (void) fprintf(output,"-inpck ");
+ else if (!(m&IGNPAR))
+ (void) fprintf(output,"-ignpar ");
+ if (m&PARMRK)
+ (void) fprintf(output,"parmrk ");
+ if (!(m&ISTRIP))
+ (void) fprintf(output,"-istrip ");
+ if (m&INLCR)
+ (void) fprintf(output,"inlcr ");
+ if (m&IGNCR)
+ (void) fprintf(output,"igncr ");
+ if (!(m&ICRNL))
+ (void) fprintf(output,"-icrnl ");
+ if (m&IUCLC)
+ (void) fprintf(output,"iuclc ");
+ if (!(m&IXON))
+ (void) fprintf(output,"-ixon ");
+ else if (m&IXANY)
+ (void) fprintf(output,"ixany ");
+ if (m&IXOFF)
+ (void) fprintf(output,"ixoff ");
+ if ((term & TERMIOS) && (m&IMAXBEL))
+ (void) fprintf(output,"imaxbel ");
+ m = cb.c_oflag;
+ if (!(m&OPOST))
+ (void) fprintf(output,"-opost ");
+ else {
+ if (m&OLCUC)
+ (void) fprintf(output,"olcuc ");
+ if (!(m&ONLCR))
+ (void) fprintf(output,"-onlcr ");
+ if (m&OCRNL)
+ (void) fprintf(output,"ocrnl ");
+ if (m&ONOCR)
+ (void) fprintf(output,"onocr ");
+ if (m&ONLRET)
+ (void) fprintf(output,"onlret ");
+ if (m&OFILL)
+ if (m&OFDEL)
+ (void) fprintf(output,"del-fill ");
+ else
+ (void) fprintf(output,"nul-fill ");
+ delay((m&CRDLY)/CR1, "cr");
+ delay((m&NLDLY)/NL1, "nl");
+ if ((m&TABDLY) == XTABS)
+ (void) fprintf(output,"-tabs ");
+ else
+ delay((m&TABDLY)/TAB1, "tab");
+ delay((m&BSDLY)/BS1, "bs");
+ delay((m&VTDLY)/VT1, "vt");
+ delay((m&FFDLY)/FF1, "ff");
+ }
+ (void) fprintf(output,"\n");
+ m = cb.c_lflag;
+ if (!(m&ISIG))
+ (void) fprintf(output,"-isig ");
+ if (!(m&ICANON))
+ (void) fprintf(output,"-icanon ");
+ if (m&XCASE)
+ (void) fprintf(output,"xcase ");
+ if (!(m&ECHO))
+ (void) fprintf(output,"-echo ");
+ if (m&ECHOE) {
+ if (m&ECHOKE)
+ (void) fprintf(output,"crt ");
+ else
+ (void) fprintf(output,"echoe -echoke ");
+ } else {
+ if (!(m&ECHOPRT))
+ (void) fprintf(output,"-echoprt ");
+ }
+ if (!(m&ECHOK))
+ (void) fprintf(output,"-echok ");
+ if (m&ECHONL)
+ (void) fprintf(output,"echonl ");
+ if (m&NOFLSH)
+ (void) fprintf(output,"noflsh ");
+ if (m&TOSTOP)
+ (void) fprintf(output,"tostop ");
+ if (!(m&ECHOCTL))
+ (void) fprintf(output,"-echoctl ");
+ if (m&DEFECHO)
+ (void) fprintf(output,"defecho ");
+ if (m&FLUSHO)
+ (void) fprintf(output,"flusho ");
+ if (m&PENDIN)
+ (void) fprintf(output,"pendin ");
+ if (m&IEXTEN)
+ (void) fprintf(output,"iexten ");
+ (void) fprintf(output,"\n");
+ }
+ if(term & FLOW) {
+ m = termiox.x_hflag;
+ if(m & RTSXOFF)
+ (void) fprintf(output,"rtsxoff ");
+ if(m & CTSXON)
+ (void) fprintf(output,"ctsxon ");
+ if(m & DTRXOFF)
+ (void) fprintf(output,"dterxoff ");
+ if(m & CDXON)
+ (void) fprintf(output,"rlsdxon ");
+ if(m & ISXOFF)
+ (void) fprintf(output,"isxoff ");
+ m = termiox.x_cflag;
+ switch(m & XMTCLK)
+ {
+ case XCIBRG: (void)fprintf(output,"xcibrg ");
+ break;
+ case XCTSET: (void)fprintf(output,"xctset ");
+ break;
+ case XCRSET: (void)fprintf(output,"xcrset ");
+ }
+
+ switch(m & RCVCLK)
+ {
+ case RCIBRG: (void)fprintf(output,"rcibrg ");
+ break;
+ case RCTSET: (void)fprintf(output,"rctset ");
+ break;
+ case RCRSET: (void)fprintf(output,"rcrset ");
+ }
+
+ switch(m & TSETCLK)
+ {
+ case TSETCOFF: (void)fprintf(output,"tsetcoff ");
+ break;
+ case TSETCRBRG: (void)fprintf(output,"tsetcrc ");
+ break;
+ case TSETCTBRG: (void)fprintf(output,"tsetcxc ");
+ }
+
+ switch(m & RSETCLK)
+ {
+ case RSETCOFF: (void)fprintf(output,"rsetcoff ");
+ break;
+ case RSETCRBRG: (void)fprintf(output,"rsetcrc ");
+ break;
+ case RSETCTBRG: (void)fprintf(output,"rsetcxc ");
+ }
+ (void) fprintf(output,"\n");
+ }
+ if(moremodes)
+ prachars();
+}
+
+pramodes(tabform) /* print all modes, -a option */
+int tabform;
+{
+ register m;
+
+ m = cb.c_cflag;
+ if(term & ASYNC) {
+ if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
+ cfgetispeed(&cb) != cfgetospeed(&cb)) {
+ prspeed("ispeed ", cfgetispeed(&cb));
+ prspeed("ospeed ", cfgetospeed(&cb));
+ } else
+ prspeed("speed ", cfgetospeed(&cb));
+ if(!(term & TERMIOS))
+ (void) fprintf(output,"line = %d; ", ocb.c_line);
+ (void) fprintf(output,"\n");
+ if(term & WINDOW) {
+ (void)fprintf(output,"rows = %d columns = %d; ", winsize.ws_row, winsize.ws_col);
+ (void)fprintf(output,"ypixels = %d xpixels = %d\n", winsize.ws_ypixel, winsize.ws_xpixel);
+ }
+ if((cb.c_lflag&ICANON)== 0)
+ (void) fprintf(output,"min = %d; time = %d;\n", cb.c_cc[VMIN],
+ cb.c_cc[VTIME]);
+ if (!tabform) {
+ pit(cb.c_cc[VINTR], "intr", "; ");
+ pit(cb.c_cc[VQUIT], "quit", "; ");
+ pit(cb.c_cc[VERASE], "erase", "; ");
+ pit(cb.c_cc[VKILL], "kill", ";\n");
+ pit(cb.c_cc[VEOF], "eof", "; ");
+ pit(cb.c_cc[VEOL], "eol", "; ");
+ pit(cb.c_cc[VEOL2], "eol2", "; ");
+ pit(cb.c_cc[VSWTCH], "swtch", ";\n");
+ if(term & TERMIOS) {
+ pit(cb.c_cc[VSTART], "start", "; ");
+ pit(cb.c_cc[VSTOP], "stop", "; ");
+ pit(cb.c_cc[VSUSP], "susp", "; ");
+ pit(cb.c_cc[VDSUSP], "dsusp", ";\n");
+ pit(cb.c_cc[VREPRINT], "rprnt", "; ");
+ pit(cb.c_cc[VDISCARD], "flush", "; ");
+ pit(cb.c_cc[VWERASE], "werase", "; ");
+ pit(cb.c_cc[VLNEXT], "lnext", ";\n");
+ }
+ }
+ } else
+ pit((unsigned)stio.tab, "ctab", "\n");
+ m = cb.c_cflag;
+ (void) fprintf(output,"-parenb "+((m&PARENB)!=0));
+ (void) fprintf(output,"-parodd "+((m&PARODD)!=0));
+ (void) fprintf(output,"cs%c ",'5'+(m&CSIZE)/CS6);
+ (void) fprintf(output,"-cstopb "+((m&CSTOPB)!=0));
+ (void) fprintf(output,"-hupcl "+((m&HUPCL)!=0));
+ (void) fprintf(output,"-cread "+((m&CREAD)!=0));
+ (void) fprintf(output,"-clocal "+((m&CLOCAL)!=0));
+
+ (void) fprintf(output,"-loblk "+((m&LOBLK)!=0));
+ if(term & TERMIOS)
+ (void) fprintf(output,"-parext "+((m&PAREXT)!=0));
+
+ (void) fprintf(output,"\n");
+ m = cb.c_iflag;
+ (void) fprintf(output,"-ignbrk "+((m&IGNBRK)!=0));
+ (void) fprintf(output,"-brkint "+((m&BRKINT)!=0));
+ (void) fprintf(output,"-ignpar "+((m&IGNPAR)!=0));
+ (void) fprintf(output,"-parmrk "+((m&PARMRK)!=0));
+ (void) fprintf(output,"-inpck "+((m&INPCK)!=0));
+ (void) fprintf(output,"-istrip "+((m&ISTRIP)!=0));
+ (void) fprintf(output,"-inlcr "+((m&INLCR)!=0));
+ (void) fprintf(output,"-igncr "+((m&IGNCR)!=0));
+ (void) fprintf(output,"-icrnl "+((m&ICRNL)!=0));
+ (void) fprintf(output,"-iuclc "+((m&IUCLC)!=0));
+ (void) fprintf(output,"\n");
+ (void) fprintf(output,"-ixon "+((m&IXON)!=0));
+ (void) fprintf(output,"-ixany "+((m&IXANY)!=0));
+ (void) fprintf(output,"-ixoff "+((m&IXOFF)!=0));
+ if(term & TERMIOS)
+ (void) fprintf(output,"-imaxbel "+((m&IMAXBEL)!=0));
+ (void) fprintf(output,"\n");
+ m = cb.c_lflag;
+ (void) fprintf(output,"-isig "+((m&ISIG)!=0));
+ (void) fprintf(output,"-icanon "+((m&ICANON)!=0));
+ (void) fprintf(output,"-xcase "+((m&XCASE)!=0));
+ (void) fprintf(output,"-echo "+((m&ECHO)!=0));
+ (void) fprintf(output,"-echoe "+((m&ECHOE)!=0));
+ (void) fprintf(output,"-echok "+((m&ECHOK)!=0));
+ (void) fprintf(output,"-echonl "+((m&ECHONL)!=0));
+ (void) fprintf(output,"-noflsh "+((m&NOFLSH)!=0));
+ if(term & TERMIOS) {
+ (void) fprintf(output,"\n");
+ (void) fprintf(output,"-tostop "+((m&TOSTOP)!=0));
+ (void) fprintf(output,"-echoctl "+((m&ECHOCTL)!=0));
+ (void) fprintf(output,"-echoprt "+((m&ECHOPRT)!=0));
+ (void) fprintf(output,"-echoke "+((m&ECHOKE)!=0));
+ (void) fprintf(output,"-defecho "+((m&DEFECHO)!=0));
+ (void) fprintf(output,"-flusho "+((m&FLUSHO)!=0));
+ (void) fprintf(output,"-pendin "+((m&PENDIN)!=0));
+ (void) fprintf(output,"-iexten "+((m&IEXTEN)!=0));
+ }
+ if(!(term & ASYNC)) {
+ (void) fprintf(output,"-stflush "+((m&STFLUSH)!=0));
+ (void) fprintf(output,"-stwrap "+((m&STWRAP)!=0));
+ (void) fprintf(output,"-stappl "+((m&STAPPL)!=0));
+ }
+ (void) fprintf(output,"\n");
+ m = cb.c_oflag;
+ (void) fprintf(output,"-opost "+((m&OPOST)!=0));
+ (void) fprintf(output,"-olcuc "+((m&OLCUC)!=0));
+ (void) fprintf(output,"-onlcr "+((m&ONLCR)!=0));
+ (void) fprintf(output,"-ocrnl "+((m&OCRNL)!=0));
+ (void) fprintf(output,"-onocr "+((m&ONOCR)!=0));
+ (void) fprintf(output,"-onlret "+((m&ONLRET)!=0));
+ (void) fprintf(output,"-ofill "+((m&OFILL)!=0));
+ (void) fprintf(output,"-ofdel "+((m&OFDEL)!=0));
+ delay((m&CRDLY)/CR1, "cr");
+ delay((m&NLDLY)/NL1, "nl");
+ if ((m&TABDLY) == XTABS)
+ (void) fprintf(output,"-tabs ");
+ else
+ delay((m&TABDLY)/TAB1, "tab");
+ delay((m&BSDLY)/BS1, "bs");
+ delay((m&VTDLY)/VT1, "vt");
+ delay((m&FFDLY)/FF1, "ff");
+ (void) fprintf(output,"\n");
+ if(term & FLOW) {
+ m = termiox.x_hflag;
+ (void) fprintf(output,"-rtsxoff "+((m&RTSXOFF)!=0));
+ (void) fprintf(output,"-ctsxon "+((m&CTSXON)!=0));
+ (void) fprintf(output,"-dterxoff "+((m&DTRXOFF)!=0));
+ (void) fprintf(output,"-rlsdxon "+((m&CDXON)!=0));
+ (void) fprintf(output,"-isxoff "+((m&ISXOFF)!=0));
+ m = termiox.x_cflag;
+ switch(m & XMTCLK)
+ {
+ case XCIBRG: (void)fprintf(output,"xcibrg ");
+ break;
+ case XCTSET: (void)fprintf(output,"xctset ");
+ break;
+ case XCRSET: (void)fprintf(output,"xcrset ");
+ }
+
+ switch(m & RCVCLK)
+ {
+ case RCIBRG: (void)fprintf(output,"rcibrg ");
+ break;
+ case RCTSET: (void)fprintf(output,"rctset ");
+ break;
+ case RCRSET: (void)fprintf(output,"rcrset ");
+ }
+
+ switch(m & TSETCLK)
+ {
+ case TSETCOFF: (void)fprintf(output,"tsetcoff ");
+ break;
+ case TSETCRBRG: (void)fprintf(output,"tsetcrc ");
+ break;
+ case TSETCTBRG: (void)fprintf(output,"tsetcxc ");
+ }
+
+ switch(m & RSETCLK)
+ {
+ case RSETCOFF: (void)fprintf(output,"rsetcoff ");
+ break;
+ case RSETCRBRG: (void)fprintf(output,"rsetcrc ");
+ break;
+ case RSETCTBRG: (void)fprintf(output,"rsetcxc ");
+ }
+ (void) fprintf(output,"\n");
+ }
+ if (tabform)
+ prachars();
+}
+
+prachars()
+{
+ if ((cb.c_lflag&ICANON)==0)
+ (void) fprintf(output,"min %d, time %d\n", cb.c_cc[VMIN],
+ cb.c_cc[VTIME]);
+ (void) fprintf(output,"\
+erase kill werase rprnt flush lnext susp intr quit stop eof\
+\n");
+ pcol(cb.c_cc[VERASE], 0);
+ pcol(cb.c_cc[VKILL], 0);
+ pcol(cb.c_cc[VWERASE], 0);
+ pcol(cb.c_cc[VREPRINT], 0);
+ pcol(cb.c_cc[VDISCARD], 0);
+ pcol(cb.c_cc[VLNEXT], 0);
+ pcol(cb.c_cc[VSUSP], cb.c_cc[VDSUSP]);
+ pcol(cb.c_cc[VINTR], 0);
+ pcol(cb.c_cc[VQUIT], 0);
+ pcol(cb.c_cc[VSTOP], cb.c_cc[VSTART]);
+ if (cb.c_lflag&ICANON)
+ pcol(cb.c_cc[VEOF], cb.c_cc[VEOL]);
+ (void) fprintf(output,"\n");
+ if (cb.c_cc[VEOL2] != 0 || cb.c_cc[VSWTCH] != 0) {
+ (void) fprintf(output,"\
+eol2 swtch\
+\n");
+ pcol(cb.c_cc[VEOL2], 0);
+ pcol(cb.c_cc[VSWTCH], 0);
+ (void) fprintf(output,"\n");
+ }
+}
+
+pcol(ch1, ch2)
+ int ch1, ch2;
+{
+ int nout = 0;
+
+ ch1 &= 0377;
+ ch2 &= 0377;
+ if (ch1 == ch2)
+ ch2 = 0;
+ for (; ch1 != 0 || ch2 != 0; ch1 = ch2, ch2 = 0) {
+ if (ch1 == 0)
+ continue;
+ if (ch1 & 0200 && !isprint(ch1)) {
+ (void) fprintf(output,"M-");
+ nout += 2;
+ ch1 &= ~ 0200;
+ }
+ if (ch1 == 0177) {
+ (void) fprintf(output,"^");
+ nout++;
+ ch1 = '?';
+ } else if (ch1 < ' ') {
+ (void) fprintf(output,"^");
+ nout++;
+ ch1 += '@';
+ }
+ (void) fprintf(output,"%c", ch1);
+ nout++;
+ if (ch2 != 0) {
+ (void) fprintf(output,"/");
+ nout++;
+ }
+ }
+ while (nout < 7) {
+ (void) fprintf(output," ");
+ nout++;
+ }
+}
+
+
+pit(what, itsname, sep) /*print function for prmodes() and pramodes() */
+ unsigned char what;
+ char *itsname, *sep;
+{
+
+ pitt++;
+ (void) fprintf(output,"%s", itsname);
+ if ((term & TERMIOS) && what == _POSIX_VDISABLE || !(term & TERMIOS) && what == 0200) {
+ (void) fprintf(output," = <undef>%s", sep);
+ return;
+ }
+ (void) fprintf(output," = ");
+ if (what & 0200 && !isprint(what)) {
+ (void) fprintf(output,"-");
+ what &= ~ 0200;
+ }
+ if (what == 0177) {
+ (void) fprintf(output,"^?%s", sep);
+ return;
+ } else if (what < ' ') {
+ (void) fprintf(output,"^");
+ what += '`';
+ }
+ (void) fprintf(output,"%c%s", what, sep);
+}
+
+delay(m, s)
+char *s;
+{
+ if(m)
+ (void) fprintf(output,"%s%d ", s, m);
+}
+
+long speed[] = {
+ 0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400,
+ 57600,76800,115200,153600,230400,307200,460800
+};
+
+prspeed(c, s)
+char *c;
+int s;
+{
+
+ (void) fprintf(output,"%s%d baud; ", c, speed[s]);
+}
+
+ /* print current settings for use with */
+prencode() /* another stty cmd, used for -g option */
+{
+ int i, last;
+
+ /* Since the -g option is mostly used for redirecting to a file *
+ /* We must print to stdout here, not stderr */
+
+ (void) printf("%x:%x:%x:%x:",cb.c_iflag,cb.c_oflag,cb.c_cflag,cb.c_lflag);
+
+ if(term & TERMIOS)
+ /* last control slot is unused */
+ last = NCCS - 2;
+ else
+ last = NCC - 1;
+ for(i = 0; i < last; i++)
+ (void) printf("%x:", cb.c_cc[i]);
+ (void) printf("%x\n", cb.c_cc[last]);
+}
diff --git a/usr/src/ucbcmd/stty/stty.h b/usr/src/ucbcmd/stty/stty.h
new file mode 100644
index 0000000000..080ddad60d
--- /dev/null
+++ b/usr/src/ucbcmd/stty/stty.h
@@ -0,0 +1,48 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+
+#define ASYNC 1
+#define FLOW 2
+#define WINDOW 4
+#define TERMIOS 8
+
+struct speeds {
+ const char *string;
+ int speed;
+};
+
+struct mds {
+ const char *string;
+ long set;
+ long reset;
+};
+
diff --git a/usr/src/ucbcmd/stty/sttyparse.c b/usr/src/ucbcmd/stty/sttyparse.c
new file mode 100644
index 0000000000..3068ca6be0
--- /dev/null
+++ b/usr/src/ucbcmd/stty/sttyparse.c
@@ -0,0 +1,446 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <termio.h>
+#include <sys/stermio.h>
+#include <sys/termiox.h>
+#include "stty.h"
+
+static char *s_arg; /* s_arg: ptr to mode to be set */
+static int match;
+static int gct(), eq(), encode();
+
+/* set terminal modes for supplied options */
+char *
+sttyparse(argc, argv, term, ocb, cb, termiox, winsize)
+int argc;
+char *argv[];
+int term; /* type of tty device, -1 means allow all options,
+ * no sanity check
+ */
+struct termio *ocb;
+struct termios *cb;
+struct termiox *termiox;
+struct winsize *winsize;
+{
+ register i;
+ extern const struct speeds speeds[];
+ extern const struct mds lmodes[];
+ extern const struct mds nlmodes[];
+ extern const struct mds cmodes[];
+ extern const struct mds ncmodes[];
+ extern const struct mds imodes[];
+ extern const struct mds nimodes[];
+ extern const struct mds omodes[];
+ extern const struct mds hmodes[];
+ extern const struct mds clkmodes[];
+
+ while(--argc > 0) {
+
+ s_arg = *++argv;
+ match = 0;
+ if ((term & ASYNC) || term == -1) {
+ if (eqarg("erase", argc) && --argc)
+ cb->c_cc[VERASE] = gct(*++argv, term);
+ else if (eqarg("intr", argc) && --argc)
+ cb->c_cc[VINTR] = gct(*++argv, term);
+ else if (eqarg("quit", argc) && --argc)
+ cb->c_cc[VQUIT] = gct(*++argv, term);
+ else if (eqarg("eof", argc) && --argc)
+ cb->c_cc[VEOF] = gct(*++argv, term);
+ else if (eqarg("min", argc) && --argc)
+ cb->c_cc[VMIN] = atoi(*++argv);
+ else if (eqarg("eol", argc) && --argc)
+ cb->c_cc[VEOL] = gct(*++argv, term);
+ else if (eqarg("brk", argc) && --argc)
+ cb->c_cc[VEOL] = gct(*++argv, term);
+ else if (eqarg("eol2", argc) && --argc)
+ cb->c_cc[VEOL2] = gct(*++argv, term);
+ else if (eqarg("time", argc) && --argc)
+ cb->c_cc[VTIME] = atoi(*++argv);
+ else if (eqarg("kill", argc) && --argc)
+ cb->c_cc[VKILL] = gct(*++argv, term);
+ else if (eqarg("swtch", argc) && --argc)
+ cb->c_cc[VSWTCH] = gct(*++argv, term);
+ if(match)
+ continue;
+ if((term & TERMIOS) || term == -1) {
+ if (eqarg("start", argc) && --argc)
+ cb->c_cc[VSTART] = gct(*++argv, term);
+ else if (eqarg("stop", argc) && --argc)
+ cb->c_cc[VSTOP] = gct(*++argv, term);
+ else if (eqarg("susp", argc) && --argc)
+ cb->c_cc[VSUSP] = gct(*++argv, term);
+ else if (eqarg("dsusp", argc) && --argc)
+ cb->c_cc[VDSUSP] = gct(*++argv, term);
+ else if (eqarg("rprnt", argc) && --argc)
+ cb->c_cc[VREPRINT] = gct(*++argv, term);
+ else if (eqarg("flush", argc) && --argc)
+ cb->c_cc[VDISCARD] = gct(*++argv, term);
+ else if (eqarg("werase", argc) && --argc)
+ cb->c_cc[VWERASE] = gct(*++argv, term);
+ else if (eqarg("lnext", argc) && --argc)
+ cb->c_cc[VLNEXT] = gct(*++argv, term);
+ }
+ if(match)
+ continue;
+ if (eq("ek")) {
+ cb->c_cc[VERASE] = CERASE;
+ cb->c_cc[VKILL] = CKILL;
+ }
+ else if (eq("crt") || eq("newcrt")) {
+ cb->c_lflag &= ~ECHOPRT;
+ cb->c_lflag |= ECHOE|ECHOCTL;
+ if (cfgetospeed(cb) >= B1200)
+ cb->c_lflag |= ECHOKE;
+ }
+ else if (eq("dec")) {
+ cb->c_cc[VERASE] = 0177;
+ cb->c_cc[VKILL] = CTRL('u');
+ cb->c_cc[VINTR] = CTRL('c');
+ cb->c_lflag &= ~ECHOPRT;
+ cb->c_lflag |= ECHOE|ECHOCTL|IEXTEN;
+ if (cfgetospeed(cb) >= B1200)
+ cb->c_lflag |= ECHOKE;
+ }
+ else if (eqarg("line", argc) && (!(term & TERMIOS) || term == -1) && --argc) {
+ ocb->c_line = atoi(*++argv);
+ continue;
+ }
+ else if (eq("raw") || eq("cbreak")) {
+ cb->c_cc[VMIN] = 1;
+ cb->c_cc[VTIME] = 0;
+ }
+ else if (eq("-raw") || eq("-cbreak") || eq("cooked")) {
+ cb->c_cc[VEOF] = CEOF;
+ cb->c_cc[VEOL] = CNUL;
+ }
+ else if(eq("sane")) {
+ cb->c_cc[VERASE] = CERASE;
+ cb->c_cc[VKILL] = CKILL;
+ cb->c_cc[VQUIT] = CQUIT;
+ cb->c_cc[VINTR] = CINTR;
+ cb->c_cc[VEOF] = CEOF;
+ cb->c_cc[VEOL] = CNUL;
+ /* SWTCH purposely not set */
+ }
+ else if((term & TERMIOS) && eqarg("ospeed", argc) && --argc) {
+ s_arg = *++argv;
+ match = 0;
+ for(i=0; speeds[i].string; i++)
+ if(eq(speeds[i].string))
+ cfsetospeed(cb, speeds[i].speed);
+ if(!match)
+ return s_arg;
+ continue;
+ }
+ else if((term & TERMIOS) && eqarg("ispeed", argc) && --argc) {
+ s_arg = *++argv;
+ match = 0;
+ for(i=0; speeds[i].string; i++)
+ if(eq(speeds[i].string))
+ cfsetispeed(cb, speeds[i].speed);
+ if(!match)
+ return s_arg;
+ continue;
+ }
+ else if (argc == 0) {
+ (void) fprintf(stderr, "stty: No argument for \"%s\"\n", s_arg);
+ exit(1);
+ }
+ for(i=0; speeds[i].string; i++)
+ if(eq(speeds[i].string)) {
+ cfsetospeed(cb, B0);
+ cfsetispeed(cb, B0);
+ cfsetospeed(cb, speeds[i].speed);
+ }
+ }
+ if ((!(term & ASYNC) || term == -1) && eqarg("ctab", argc) && --argc) {
+ cb->c_cc[7] = gct(*++argv, term);
+ continue;
+ }
+ else if (argc == 0) {
+ (void) fprintf(stderr, "stty: No argument for \"%s\"\n", s_arg);
+ exit(1);
+ }
+
+ for(i=0; imodes[i].string; i++)
+ if(eq(imodes[i].string)) {
+ cb->c_iflag &= ~imodes[i].reset;
+ cb->c_iflag |= imodes[i].set;
+ }
+ if((term & TERMIOS) || term == -1) {
+ for(i=0; nimodes[i].string; i++)
+ if(eq(nimodes[i].string)) {
+ cb->c_iflag &= ~nimodes[i].reset;
+ cb->c_iflag |= nimodes[i].set;
+ }
+ }
+
+ for(i=0; omodes[i].string; i++)
+ if(eq(omodes[i].string)) {
+ cb->c_oflag &= ~omodes[i].reset;
+ cb->c_oflag |= omodes[i].set;
+ }
+ if((!(term & ASYNC) || term == -1) && eq("sane")) {
+ cb->c_oflag |= TAB3;
+ continue;
+ }
+ for(i=0; cmodes[i].string; i++)
+ if(eq(cmodes[i].string)) {
+ cb->c_cflag &= ~cmodes[i].reset;
+ cb->c_cflag |= cmodes[i].set;
+ }
+ if((term & TERMIOS) || term == -1)
+ for(i=0; ncmodes[i].string; i++)
+ if(eq(ncmodes[i].string)) {
+ cb->c_cflag &= ~ncmodes[i].reset;
+ cb->c_cflag |= ncmodes[i].set;
+ }
+ for(i=0; lmodes[i].string; i++)
+ if(eq(lmodes[i].string)) {
+ cb->c_lflag &= ~lmodes[i].reset;
+ cb->c_lflag |= lmodes[i].set;
+ }
+ if((term & TERMIOS) || term == -1)
+ for(i=0; nlmodes[i].string; i++)
+ if(eq(nlmodes[i].string)) {
+ cb->c_lflag &= ~nlmodes[i].reset;
+ cb->c_lflag |= nlmodes[i].set;
+ }
+ if((term & FLOW) || term == -1) {
+ for(i=0; hmodes[i].string; i++)
+ if(eq(hmodes[i].string)) {
+ termiox->x_hflag &= ~hmodes[i].reset;
+ termiox->x_hflag |= hmodes[i].set;
+ }
+ for(i=0; clkmodes[i].string; i++)
+ if(eq(clkmodes[i].string)) {
+ termiox->x_cflag &= ~clkmodes[i].reset;
+ termiox->x_cflag |= clkmodes[i].set;
+ }
+
+ }
+ if(eqarg("rows", argc) && --argc)
+ winsize->ws_row = atoi(*++argv);
+ else if((eqarg("columns", argc) || eqarg("cols", argc)) && --argc)
+ winsize->ws_col = atoi(*++argv);
+ else if(eqarg("xpixels", argc) && --argc)
+ winsize->ws_xpixel = atoi(*++argv);
+ else if(eqarg("ypixels", argc) && --argc)
+ winsize->ws_ypixel = atoi(*++argv);
+ else if (argc == 0) {
+ (void) fprintf(stderr, "stty: No argument for \"%s\"\n", s_arg);
+ exit(1);
+ }
+ if(!match)
+ if(!encode(cb, term)) {
+ return(s_arg); /* parsing failed */
+ }
+ }
+ return((char *)0);
+}
+
+static int eq(string)
+char *string;
+{
+ register i;
+
+ if(!s_arg)
+ return(0);
+ i = 0;
+loop:
+ if(s_arg[i] != string[i])
+ return(0);
+ if(s_arg[i++] != '\0')
+ goto loop;
+ match++;
+ return(1);
+}
+
+/* Checks for options that require an argument */
+static int
+eqarg(string, argc)
+char *string;
+int argc;
+{
+ int status;
+
+ if ((status = eq(string)) == 1) {
+ if (argc <= 1) {
+ (void) fprintf(stderr, "stty: No argument for \"%s\"\n",
+ s_arg);
+ exit(1);
+ }
+ }
+ return(status);
+}
+
+/* get pseudo control characters from terminal */
+/* and convert to internal representation */
+static int gct(cp, term)
+register char *cp;
+int term;
+{
+ register c;
+
+ c = *cp++;
+ if (c == '^') {
+ c = *cp;
+ if (c == '?')
+ c = 0177; /* map '^?' to DEL */
+ else if (c == '-')
+ c = (term & TERMIOS) ? _POSIX_VDISABLE : 0200; /* map '^-' to undefined */
+ else
+ c &= 037;
+ }
+ return(c);
+}
+
+/* get modes of tty device and fill in applicable structures */
+int
+get_ttymode(fd, termio, termios, stermio, termiox, winsize)
+int fd;
+struct termio *termio;
+struct termios *termios;
+struct stio *stermio;
+struct termiox *termiox;
+struct winsize *winsize;
+{
+ int i;
+ int term = 0;
+ if(ioctl(fd, STGET, stermio) == -1) {
+ term |= ASYNC;
+ if(ioctl(fd, TCGETS, termios) == -1) {
+ if(ioctl(fd, TCGETA, termio) == -1)
+ return -1;
+ termios->c_lflag = termio->c_lflag;
+ termios->c_oflag = termio->c_oflag;
+ termios->c_iflag = termio->c_iflag;
+ termios->c_cflag = termio->c_cflag;
+ for(i = 0; i < NCC; i++)
+ termios->c_cc[i] = termio->c_cc[i];
+ } else
+ term |= TERMIOS;
+ }
+ else {
+ termios->c_cc[7] = (unsigned)stermio->tab;
+ termios->c_lflag = stermio->lmode;
+ termios->c_oflag = stermio->omode;
+ termios->c_iflag = stermio->imode;
+ }
+
+ if(ioctl(fd, TCGETX, termiox) == 0)
+ term |= FLOW;
+
+ if(ioctl(fd, TIOCGWINSZ, winsize) == 0)
+ term |= WINDOW;
+ return term;
+}
+
+/* set tty modes */
+int
+set_ttymode(fd, term, termio, termios, stermio, termiox, winsize, owinsize)
+int fd, term;
+struct termio *termio;
+struct termios *termios;
+struct stio *stermio;
+struct termiox *termiox;
+struct winsize *winsize, *owinsize;
+{
+ int i;
+ if (term & ASYNC) {
+ if(term & TERMIOS) {
+ if(ioctl(fd, TCSETSW, termios) == -1)
+ return -1;
+ } else {
+ termio->c_lflag = termios->c_lflag;
+ termio->c_oflag = termios->c_oflag;
+ termio->c_iflag = termios->c_iflag;
+ termio->c_cflag = termios->c_cflag;
+ for(i = 0; i < NCC; i++)
+ termio->c_cc[i] = termios->c_cc[i];
+ if(ioctl(fd, TCSETAW, termio) == -1)
+ return -1;
+ }
+
+ } else {
+ stermio->imode = termios->c_iflag;
+ stermio->omode = termios->c_oflag;
+ stermio->lmode = termios->c_lflag;
+ stermio->tab = termios->c_cc[7];
+ if (ioctl(fd, STSET, stermio) == -1)
+ return -1;
+ }
+ if(term & FLOW) {
+ if(ioctl(fd, TCSETXW, termiox) == -1)
+ return -1;
+ }
+ if((owinsize->ws_col != winsize->ws_col
+ || owinsize->ws_row != winsize->ws_row)
+ && ioctl(0, TIOCSWINSZ, winsize) != 0)
+ return -1;
+ return 0;
+}
+
+static int encode(cb, term)
+struct termios *cb;
+int term;
+{
+ unsigned long grab[20], i;
+ int last;
+ i = sscanf(s_arg,
+ "%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx:%lx",
+ &grab[0],&grab[1],&grab[2],&grab[3],&grab[4],&grab[5],&grab[6],
+ &grab[7],&grab[8],&grab[9],&grab[10],&grab[11],
+ &grab[12], &grab[13], &grab[14], &grab[15],
+ &grab[16], &grab[17], &grab[18], &grab[19]);
+
+ if((term & TERMIOS) && i < 20 && term != -1 || i < 12)
+ return(0);
+ cb->c_iflag = grab[0];
+ cb->c_oflag = grab[1];
+ cb->c_cflag = grab[2];
+ cb->c_lflag = grab[3];
+
+ if(term & TERMIOS)
+ last = NCCS - 1;
+ else
+ last = NCC;
+ for(i=0; i<last; i++)
+ cb->c_cc[i] = (unsigned char) grab[i+4];
+ return(1);
+}
+
diff --git a/usr/src/ucbcmd/stty/sttytable.c b/usr/src/ucbcmd/stty/sttytable.c
new file mode 100644
index 0000000000..9f1539123b
--- /dev/null
+++ b/usr/src/ucbcmd/stty/sttytable.c
@@ -0,0 +1,334 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1995 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <termio.h>
+#include <sys/stermio.h>
+#include <sys/termiox.h>
+#include "stty.h"
+
+const struct speeds speeds[] = {
+ "0", B0,
+ "50", B50,
+ "75", B75,
+ "110", B110,
+ "134", B134,
+ "134.5",B134,
+ "150", B150,
+ "200", B200,
+ "300", B300,
+ "600", B600,
+ "1200", B1200,
+ "1800", B1800,
+ "2400", B2400,
+ "4800", B4800,
+ "9600", B9600,
+ "19200", B19200,
+ "19.2", B19200,
+ "exta", EXTA,
+ "38400", B38400,
+ "38.4", B38400,
+ "extb", EXTB,
+ "57600", B57600,
+ "76800", B76800,
+ "115200", B115200,
+ "153600", B153600,
+ "230400", B230400,
+ "307200", B307200,
+ "460800", B460800,
+ 0,
+};
+ /* Control Modes */
+const struct mds cmodes[] = {
+ "-parity", CS8, PARENB|CSIZE,
+ "-evenp", CS8, PARENB|CSIZE,
+ "-even", CS8, PARENB|CSIZE,
+ "-oddp", CS8, PARENB|PARODD|CSIZE,
+ "-odd", CS8, PARENB|PARODD|CSIZE,
+ "parity", PARENB|CS7, PARODD|CSIZE,
+ "evenp", PARENB|CS7, PARODD|CSIZE,
+ "even", PARENB|CS7, PARODD|CSIZE,
+ "oddp", PARENB|PARODD|CS7, CSIZE,
+ "odd", PARENB|PARODD|CS7, CSIZE,
+ "parenb", PARENB, 0,
+ "-parenb", 0, PARENB,
+ "parodd", PARODD, 0,
+ "-parodd", 0, PARODD,
+ "cs8", CS8, CSIZE,
+ "cs7", CS7, CSIZE,
+ "cs6", CS6, CSIZE,
+ "cs5", CS5, CSIZE,
+ "cstopb", CSTOPB, 0,
+ "-cstopb", 0, CSTOPB,
+ "hupcl", HUPCL, 0,
+ "hup", HUPCL, 0,
+ "-hupcl", 0, HUPCL,
+ "-hup", 0, HUPCL,
+ "clocal", CLOCAL, 0,
+ "-clocal", 0, CLOCAL,
+ "loblk", LOBLK, 0,
+ "-loblk", 0, LOBLK,
+ "cread", CREAD, 0,
+ "-cread", 0, CREAD,
+ "litout", CS8, (CSIZE|PARENB),
+ "-litout", (CS7|PARENB), CSIZE,
+ "pass8", CS8, (CSIZE|PARENB),
+ "-pass8", (CS7|PARENB), CSIZE,
+ "raw", CS8, (CSIZE|PARENB),
+ "-raw", (CS7|PARENB), CSIZE,
+ "cooked", (CS7|PARENB), CSIZE,
+ "sane", (CS7|PARENB|CREAD), (CSIZE|PARODD|CLOCAL),
+ 0
+};
+
+const struct mds ncmodes[] = {
+ "parext", PAREXT, 0,
+ "-parext", 0, PAREXT,
+ "markp", (PARENB|PARODD|CS7|PAREXT), CSIZE,
+ "-markp", CS8, (PARENB|PARODD|CSIZE|PAREXT),
+ "spacep", (PARENB|CS7|PAREXT), PARODD|CSIZE,
+ "-spacep", CS8, (PARENB|CSIZE|PAREXT),
+ 0
+};
+ /* Input Modes */
+const struct mds imodes[] = {
+ "ignbrk", IGNBRK, 0,
+ "-ignbrk", 0, IGNBRK,
+ "brkint", BRKINT, 0,
+ "-brkint", 0, BRKINT,
+ "ignpar", IGNPAR, 0,
+ "-ignpar", 0, IGNPAR,
+ "parmrk", PARMRK, 0,
+ "-parmrk", 0, PARMRK,
+ "inpck", INPCK, 0,
+ "-inpck", 0,INPCK,
+ "istrip", ISTRIP, 0,
+ "-istrip", 0, ISTRIP,
+ "inlcr", INLCR, 0,
+ "-inlcr", 0, INLCR,
+ "igncr", IGNCR, 0,
+ "-igncr", 0, IGNCR,
+ "icrnl", ICRNL, 0,
+ "-icrnl", 0, ICRNL,
+ "-nl", ICRNL, (INLCR|IGNCR),
+ "nl", 0, ICRNL,
+ "iuclc", IUCLC, 0,
+ "-iuclc", 0, IUCLC,
+ "lcase", IUCLC, 0,
+ "-lcase", 0, IUCLC,
+ "LCASE", IUCLC, 0,
+ "-LCASE", 0, IUCLC,
+ "ixon", IXON, 0,
+ "-ixon", 0, IXON,
+ "ixany", IXANY, 0,
+ "-ixany", 0, IXANY,
+ "decctlq", 0, IXANY,
+ "-decctlq", IXANY, 0,
+ "ixoff", IXOFF, 0,
+ "-ixoff", 0, IXOFF,
+ "tandem", IXOFF, 0,
+ "-tandem", 0, IXOFF,
+ "pass8", 0, ISTRIP,
+ "-pass8", ISTRIP, 0,
+ "raw", 0, -1,
+ "-raw", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IMAXBEL), 0,
+ "cooked", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), 0,
+ "sane", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IMAXBEL),
+ (IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF),
+ 0
+};
+
+const struct mds nimodes[] = {
+ "imaxbel", IMAXBEL, 0,
+ "-imaxbel", 0, IMAXBEL,
+ 0
+};
+ /* Local Modes */
+const struct mds lmodes[] = {
+ "isig", ISIG, 0,
+ "-isig", 0, ISIG,
+ "icanon", ICANON, 0,
+ "-icanon", 0, ICANON,
+ "cbreak", 0, ICANON,
+ "-cbreak", ICANON, 0,
+ "xcase", XCASE, 0,
+ "-xcase", 0, XCASE,
+ "lcase", XCASE, 0,
+ "-lcase", 0, XCASE,
+ "LCASE", XCASE, 0,
+ "-LCASE", 0, XCASE,
+ "echo", ECHO, 0,
+ "-echo", 0, ECHO,
+ "echoe", ECHOE, 0,
+ "-echoe", 0, ECHOE,
+ "crterase", ECHOE, 0,
+ "-crterase", 0, ECHOE,
+ "echok", ECHOK, 0,
+ "-echok", 0, ECHOK,
+ "lfkc", ECHOK, 0,
+ "-lfkc", 0, ECHOK,
+ "echonl", ECHONL, 0,
+ "-echonl", 0, ECHONL,
+ "noflsh", NOFLSH, 0,
+ "-noflsh", 0, NOFLSH,
+ "raw", 0, (ISIG|ICANON|XCASE|IEXTEN),
+ "-raw", (ISIG|ICANON|IEXTEN), 0,
+ "cooked", (ISIG|ICANON), 0,
+ "sane", (ISIG|ICANON|IEXTEN|ECHO|ECHOK|ECHOE|ECHOCTL|ECHOKE),
+ (XCASE|ECHONL|NOFLSH|STFLUSH|STWRAP|STAPPL),
+ "stflush", STFLUSH, 0,
+ "-stflush", 0, STFLUSH,
+ "stwrap", STWRAP, 0,
+ "-stwrap", 0, STWRAP,
+ "stappl", STAPPL, 0,
+ "-stappl", 0, STAPPL,
+ 0,
+};
+
+const struct mds nlmodes[] = {
+ "tostop", TOSTOP, 0,
+ "-tostop", 0, TOSTOP,
+ "echoctl", ECHOCTL, 0,
+ "-echoctl", 0, ECHOCTL,
+ "ctlecho", ECHOCTL, 0,
+ "-ctlecho", 0, ECHOCTL,
+ "echoprt", ECHOPRT, 0,
+ "-echoprt", 0, ECHOPRT,
+ "prterase", ECHOPRT, 0,
+ "-prterase", 0, ECHOPRT,
+ "echoke", ECHOKE, 0,
+ "-echoke", 0, ECHOKE,
+ "crtkill", ECHOKE, 0,
+ "-crtkill", 0, ECHOKE,
+ "defecho", DEFECHO, 0,
+ "-defecho", 0, DEFECHO,
+ "flusho", FLUSHO, 0,
+ "-flusho", 0, FLUSHO,
+ "pendin", PENDIN, 0,
+ "-pendin", 0, PENDIN,
+ "iexten", IEXTEN, 0,
+ "-iexten", 0, IEXTEN,
+ 0
+};
+ /* Output Modes */
+const struct mds omodes[] = {
+ "opost", OPOST, 0,
+ "-opost", 0, OPOST,
+ "olcuc", OLCUC, 0,
+ "-olcuc", 0, OLCUC,
+ "lcase", OLCUC, 0,
+ "-lcase", 0, OLCUC,
+ "LCASE", OLCUC, 0,
+ "-LCASE", 0, OLCUC,
+ "onlcr", ONLCR, 0,
+ "-onlcr", 0, ONLCR,
+ "-nl", ONLCR, (OCRNL|ONLRET),
+ "nl", 0, ONLCR,
+ "ocrnl", OCRNL, 0,
+ "-ocrnl",0, OCRNL,
+ "onocr", ONOCR, 0,
+ "-onocr", 0, ONOCR,
+ "onlret", ONLRET, 0,
+ "-onlret", 0, ONLRET,
+ "fill", OFILL, OFDEL,
+ "-fill", 0, OFILL|OFDEL,
+ "nul-fill", OFILL, OFDEL,
+ "del-fill", OFILL|OFDEL, 0,
+ "ofill", OFILL, 0,
+ "-ofill", 0, OFILL,
+ "ofdel", OFDEL, 0,
+ "-ofdel", 0, OFDEL,
+ "cr0", CR0, CRDLY,
+ "cr1", CR1, CRDLY,
+ "cr2", CR2, CRDLY,
+ "cr3", CR3, CRDLY,
+ "tab0", TAB0, TABDLY,
+ "tabs", TAB0, TABDLY,
+ "tab1", TAB1, TABDLY,
+ "tab2", TAB2, TABDLY,
+ "tab3", TAB3, TABDLY,
+ "-tabs", TAB3, TABDLY,
+ "nl0", NL0, NLDLY,
+ "nl1", NL1, NLDLY,
+ "ff0", FF0, FFDLY,
+ "ff1", FF1, FFDLY,
+ "vt0", VT0, VTDLY,
+ "vt1", VT1, VTDLY,
+ "bs0", BS0, BSDLY,
+ "bs1", BS1, BSDLY,
+ "litout", 0, OPOST,
+ "-litout", OPOST, 0,
+ "raw", 0, OPOST,
+ "-raw", OPOST, 0,
+ "cooked", OPOST, 0,
+ "tty33", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
+ "tn300", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
+ "ti700", CR2, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
+ "vt05", NL1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
+ "tek", FF1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
+ "tty37", (FF1|VT1|CR2|TAB1|NL1), (NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
+ "sane", (OPOST|ONLCR), (OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL|
+ NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
+ 0,
+};
+
+const struct mds hmodes[] = {
+ "-rtsxoff", 0, RTSXOFF,
+ "rtsxoff", RTSXOFF, 0,
+ "-ctsxon", 0, CTSXON,
+ "ctsxon", CTSXON, 0,
+ "-dterxoff", 0, DTRXOFF,
+ "dterxoff", DTRXOFF, 0,
+ "-rlsdxon", 0, CDXON,
+ "rlsdxon", CDXON, 0,
+ "-isxoff", 0, ISXOFF,
+ "isxoff", ISXOFF, 0,
+ 0,
+};
+
+const struct mds clkmodes[] = {
+ "xcibrg", XCIBRG, XMTCLK,
+ "xctset", XCTSET, XMTCLK,
+ "xcrset", XCRSET, XMTCLK,
+ "rcibrg", RCIBRG, RCVCLK,
+ "rctset", RCTSET, RCVCLK,
+ "rcrset", RCRSET, RCVCLK,
+ "tsetcoff", TSETCOFF, TSETCLK,
+ "tsetcrc", TSETCRBRG, TSETCLK,
+ "tsetcxc", TSETCTBRG, TSETCLK,
+ "rsetcoff", RSETCOFF, RSETCLK,
+ "rsetcrc", RSETCRBRG, RSETCLK,
+ "rsetcxc", RSETCTBRG, RSETCLK,
+ "async", XCIBRG|RCIBRG|TSETCOFF|RSETCOFF, XMTCLK|RCVCLK|TSETCLK|RSETCLK,
+ 0,
+};
diff --git a/usr/src/ucbcmd/sum/Makefile b/usr/src/ucbcmd/sum/Makefile
new file mode 100644
index 0000000000..4d9b9a556e
--- /dev/null
+++ b/usr/src/ucbcmd/sum/Makefile
@@ -0,0 +1,46 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989,1996 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+
+PROG= sum
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/sum/sum.c b/usr/src/ucbcmd/sum/sum.c
new file mode 100644
index 0000000000..1ee2cbc203
--- /dev/null
+++ b/usr/src/ucbcmd/sum/sum.c
@@ -0,0 +1,65 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983,1984,1985,1986,1987,1988,1996, by Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * Sum bytes in file mod 2^16
+ */
+
+#include <stdio.h>
+
+main(argc,argv)
+char **argv;
+{
+ register unsigned sum;
+ register i, c;
+ register FILE *f;
+ register long long nbytes;
+ int errflg = 0;
+
+ i = 1;
+ do {
+ if(i < argc) {
+ if ((f = fopen(argv[i], "r")) == NULL) {
+ fprintf(stderr, "sum: Can't open %s\n", argv[i]);
+ errflg += 10;
+ continue;
+ }
+ } else
+ f = stdin;
+ sum = 0;
+ nbytes = 0;
+ while ((c = getc(f)) != EOF) {
+ nbytes++;
+ if (sum&01)
+ sum = (sum>>1) + 0x8000;
+ else
+ sum >>= 1;
+ sum += c;
+ sum &= 0xFFFF;
+ }
+ if (ferror(f)) {
+ errflg++;
+ fprintf(stderr, "sum: read error on %s\n", argc>1?argv[i]:"-");
+ }
+ printf("%05u %5lld", sum, (nbytes+BUFSIZ-1)/BUFSIZ);
+ if(argc > 2)
+ printf(" %s", argv[i]);
+ printf("\n");
+ fclose(f);
+ } while(++i < argc);
+ exit(errflg);
+}
diff --git a/usr/src/ucbcmd/test/Makefile b/usr/src/ucbcmd/test/Makefile
new file mode 100644
index 0000000000..89cf95fe31
--- /dev/null
+++ b/usr/src/ucbcmd/test/Makefile
@@ -0,0 +1,47 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989,1996, by Sun Microsystems, Inc.
+# All rights reserved.
+#
+
+PROG= test
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/test/test.c b/usr/src/ucbcmd/test/test.c
new file mode 100644
index 0000000000..0e98ef8c65
--- /dev/null
+++ b/usr/src/ucbcmd/test/test.c
@@ -0,0 +1,276 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/* Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * test expression
+ * [ expression ]
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#define EQ(a,b) ((strcmp(a,b)==0))
+
+int ap;
+int ac;
+char **av;
+
+char *nxtarg();
+
+main(argc, argv)
+char *argv[];
+{
+ int status;
+
+ ac = argc; av = argv; ap = 1;
+ if(EQ(argv[0],"[")) {
+ if(!EQ(argv[--ac],"]"))
+ synbad("] missing","");
+ }
+ argv[ac] = 0;
+ if (ac<=1) exit(1);
+ status = (exp()?0:1);
+ if (nxtarg(1)!=0)
+ synbad("too many arguments","");
+ exit(status);
+}
+
+char *nxtarg(mt) {
+
+ if (ap>=ac) {
+ if(mt) {
+ ap++;
+ return(0);
+ }
+ synbad("argument expected","");
+ }
+ return(av[ap++]);
+}
+
+exp() {
+ int p1;
+ char *p2;
+
+ p1 = e1();
+ p2 = nxtarg(1);
+ if (p2 != 0) {
+ if (EQ(p2, "-o"))
+ return(p1 | exp());
+ if (EQ(p2, "]"))
+ synbad("syntax error","");
+ }
+ ap--;
+ return(p1);
+}
+
+e1() {
+ int p1;
+ char *p2;
+
+ p1 = e2();
+ p2 = nxtarg(1);
+ if ((p2 != 0) && EQ(p2, "-a"))
+ return(p1 & e1());
+ ap--;
+ return(p1);
+}
+
+e2() {
+ if (EQ(nxtarg(0), "!"))
+ return(!e3());
+ ap--;
+ return(e3());
+}
+
+e3() {
+ int p1;
+ register char *a;
+ char *p2;
+ int int1, int2;
+
+ a=nxtarg(0);
+ if(EQ(a, "(")) {
+ p1 = exp();
+ if(!EQ(nxtarg(0), ")")) synbad(") expected","");
+ return(p1);
+ }
+ p2 = nxtarg(1);
+ ap--;
+ if ((p2 == 0) || (!EQ(p2, "=") && !EQ(p2, "!="))) {
+ if(EQ(a, "-r"))
+ return(tio(nxtarg(0), 4));
+
+ if(EQ(a, "-w"))
+ return(tio(nxtarg(0), 2));
+
+ if(EQ(a, "-x"))
+ return(tio(nxtarg(0), 1));
+
+ if(EQ(a, "-d"))
+ return(filtyp(nxtarg(0), S_IFDIR));
+
+ if(EQ(a, "-c"))
+ return(filtyp(nxtarg(0), S_IFCHR));
+
+ if(EQ(a, "-b"))
+ return(filtyp(nxtarg(0), S_IFBLK));
+
+ if(EQ(a, "-f")) {
+ struct stat statb;
+
+ return(stat(nxtarg(0), &statb) >= 0 &&
+ (statb.st_mode & S_IFMT) != S_IFDIR);
+ }
+
+ if(EQ(a, "-h"))
+ return(filtyp(nxtarg(0), S_IFLNK));
+
+ if(EQ(a, "-u"))
+ return(ftype(nxtarg(0), S_ISUID));
+
+ if(EQ(a, "-g"))
+ return(ftype(nxtarg(0), S_ISGID));
+
+ if(EQ(a, "-k"))
+ return(ftype(nxtarg(0), S_ISVTX));
+
+ if(EQ(a, "-p"))
+#ifdef S_IFIFO
+ return(filtyp(nxtarg(0), S_IFIFO));
+#else
+ return(nxtarg(0), 0);
+#endif
+
+ if(EQ(a, "-s"))
+ return(fsizep(nxtarg(0)));
+
+ if(EQ(a, "-t"))
+ if(ap>=ac)
+ return(isatty(1));
+ else if (EQ((a = nxtarg(0)), "-a") || EQ(a, "-o")) {
+ ap--;
+ return(isatty(1));
+ } else
+ return(isatty(atoi(a)));
+
+ if(EQ(a, "-n"))
+ return(!EQ(nxtarg(0), ""));
+ if(EQ(a, "-z"))
+ return(EQ(nxtarg(0), ""));
+ }
+
+ p2 = nxtarg(1);
+ if (p2==0)
+ return(!EQ(a,""));
+ if (EQ(p2, "-a") || EQ(p2, "-o")) {
+ ap--;
+ return(!EQ(a,""));
+ }
+ if(EQ(p2, "="))
+ return(EQ(nxtarg(0), a));
+
+ if(EQ(p2, "!="))
+ return(!EQ(nxtarg(0), a));
+
+ int1 = atoi(a);
+ int2 = atoi(nxtarg(0));
+ if(EQ(p2, "-eq"))
+ return(int1==int2);
+ if(EQ(p2, "-ne"))
+ return(int1!=int2);
+ if(EQ(p2, "-gt"))
+ return(int1>int2);
+ if(EQ(p2, "-lt"))
+ return(int1<int2);
+ if(EQ(p2, "-ge"))
+ return(int1>=int2);
+ if(EQ(p2, "-le"))
+ return(int1<=int2);
+
+ synbad("unknown operator ",p2);
+ /* NOTREACHED */
+}
+
+tio(a, f)
+char *a;
+int f;
+{
+
+ if (access(a, f) == 0)
+ return(1);
+ else
+ return(0);
+}
+
+ftype(f, field)
+char *f;
+int field;
+{
+ struct stat statb;
+
+ if(stat(f,&statb)<0)
+ return(0);
+ if((statb.st_mode&field)==field)
+ return(1);
+ return(0);
+}
+
+filtyp(f, field)
+char *f;
+int field;
+{
+ struct stat statb;
+
+ if (field == S_IFLNK) {
+ if(lstat(f,&statb)<0)
+ return(0);
+ } else {
+ if(stat(f,&statb)<0)
+ return(0);
+ }
+ if((statb.st_mode&S_IFMT)==field)
+ return(1);
+ else
+ return(0);
+}
+
+fsizep(f)
+char *f;
+{
+ struct stat statb;
+
+ if(stat(f,&statb)<0)
+ return(0);
+ return(statb.st_size>0);
+}
+
+synbad(s1,s2)
+char *s1, *s2;
+{
+ (void) write(2, "test: ", 6);
+ (void) write(2, s1, strlen(s1));
+ (void) write(2, s2, strlen(s2));
+ (void) write(2, "\n", 1);
+ exit(255);
+}
+
+length(s)
+ char *s;
+{
+ char *es=s;
+ while(*es++);
+ return(es-s-1);
+}
diff --git a/usr/src/ucbcmd/touch/Makefile b/usr/src/ucbcmd/touch/Makefile
new file mode 100644
index 0000000000..8207a9be32
--- /dev/null
+++ b/usr/src/ucbcmd/touch/Makefile
@@ -0,0 +1,48 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright (c) 1996, by Sun Microsystems, Inc.
+# All rights reserved.
+#
+
+#
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0
+#
+
+PROG= touch
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/touch/touch.c b/usr/src/ucbcmd/touch/touch.c
new file mode 100644
index 0000000000..1eeffe8948
--- /dev/null
+++ b/usr/src/ucbcmd/touch/touch.c
@@ -0,0 +1,360 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef lint
+#pragma ident "%Z%%M% %I% %E% SMI"
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
+#include <unistd.h>
+
+#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
+
+struct stat stbuf;
+int status;
+#ifdef S5EMUL
+int dmsize[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+#endif S5EMUL
+
+static char usage[] =
+#ifdef S5EMUL
+ "[-amc] [mmddhhmm[yy]]";
+#else /*!S5EMUL*/
+ "[-amcf]";
+int force = 0;
+int nowrite;
+#endif /*!S5EMUL*/
+
+int mflg=1, aflg=1, cflg=0, nflg=0;
+char *prog;
+
+#ifdef S5EMUL
+char *cbp;
+#endif S5EMUL
+time_t time();
+off_t lseek();
+time_t timelocal(), timegm();
+struct timeval timbuf;
+static void timestruc_to_timeval(timestruc_t *, struct timeval *);
+
+#ifdef S5EMUL
+struct tm *
+gtime()
+{
+ static struct tm newtime;
+ long nt;
+
+ newtime.tm_mon = gpair() - 1;
+ newtime.tm_mday = gpair();
+ newtime.tm_hour = gpair();
+ if (newtime.tm_hour == 24) {
+ newtime.tm_hour = 0;
+ newtime.tm_mday++;
+ }
+ newtime.tm_min = gpair();
+ newtime.tm_sec = 0;
+ newtime.tm_year = gpair();
+ if (newtime.tm_year < 0) {
+ (void) time(&nt);
+ newtime.tm_year = localtime(&nt)->tm_year;
+ }
+ return (&newtime);
+}
+
+gpair()
+{
+ register int c, d;
+ register char *cp;
+
+ cp = cbp;
+ if (*cp == 0)
+ return (-1);
+ c = (*cp++ - '0') * 10;
+ if (c<0 || c>100)
+ return (-1);
+ if (*cp == 0)
+ return (-1);
+ if ((d = *cp++ - '0') < 0 || d > 9)
+ return (-1);
+ cbp = cp;
+ return (c+d);
+}
+#endif /*S5EMUL*/
+
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ register c;
+#ifdef S5EMUL
+ int days_in_month;
+ struct tm *tp;
+#endif S5EMUL
+
+ int errflg=0, optc;
+ extern char *optarg;
+ extern int optind;
+ extern int opterr;
+
+ prog = argv[0];
+ opterr = 0; /* disable getopt() error msgs */
+ while ((optc=getopt(argc, argv, "amcf")) != EOF)
+ switch (optc) {
+ case 'm':
+ mflg++;
+ aflg--;
+ break;
+ case 'a':
+ aflg++;
+ mflg--;
+ break;
+ case 'c':
+ cflg++;
+ break;
+#ifndef S5EMUL
+ case 'f':
+ force++; /* SysV version ignores -f */
+ break;
+#endif /*!S5EMUL*/
+ case '?':
+ errflg++;
+ }
+
+ if (((argc-optind) < 1) || errflg) {
+ (void) fprintf(stderr, "usage: %s %s file ...\n", prog, usage);
+ exit(2);
+ }
+ status = 0;
+
+#ifdef S5EMUL
+ if (!isnumber(argv[optind])) { /* BSD version only sets Present */
+#endif /*S5EMUL*/
+ if ((aflg <= 0) || (mflg <= 0))
+ (void) gettimeofday(&timbuf, NULL);
+ else
+ nflg++; /* no -a, -m, or date seen */
+#ifdef S5EMUL
+ } else { /* SysV version sets arbitrary date */
+ cbp = (char *)argv[optind++];
+ if ((tp = gtime()) == NULL) {
+ (void) fprintf(stderr, "%s: bad date conversion\n",
+ prog);
+ exit(2);
+ }
+ days_in_month = dmsize[tp->tm_mon];
+ if (tp->tm_mon == 1 && isleap(tp->tm_year + 1900))
+ days_in_month = 29; /* February in leap year */
+ if (tp->tm_mon < 0 || tp->tm_mon > 11 ||
+ tp->tm_mday < 1 || tp->tm_mday > days_in_month ||
+ tp->tm_hour < 0 || tp->tm_hour > 23 ||
+ tp->tm_min < 0 || tp->tm_min > 59 ||
+ tp->tm_sec < 0 || tp->tm_sec > 59) {
+ (void) fprintf(stderr, "%s: bad date conversion\n",
+ prog);
+ exit(2);
+ }
+ timbuf = timelocal(tp);
+ }
+#endif /*S5EMUL*/
+
+ for (c = optind; c < argc; c++) {
+ if (touch(argv[c]) < 0)
+ status++;
+ }
+ exit(status);
+ /* NOTREACHED */
+}
+
+int
+touch(filename)
+ char *filename;
+{
+ struct timeval times[2];
+ register int fd;
+
+ if (stat(filename, &stbuf)) {
+ /*
+ * if stat failed for reasons other than ENOENT,
+ * the file should not be created, since this
+ * can clobber the contents of an existing file
+ * (for example, a large file that results in overflow).
+ */
+ if (errno != ENOENT) {
+ (void) fprintf(stderr,"%s: cannot stat ", prog);
+ perror(filename);
+ return (-1);
+ } else if (cflg) {
+ return (-1);
+ }
+ else if ((fd = creat(filename, 0666)) < 0) {
+ (void) fprintf(stderr, "%s: cannot create ", prog);
+ perror(filename);
+ return (-1);
+ }
+ else {
+ (void) close(fd);
+ if (stat(filename, &stbuf)) {
+ (void) fprintf(stderr,"%s: cannot stat ", prog);
+ perror(filename);
+ return (-1);
+ }
+ }
+ if (nflg)
+ return (0);
+ }
+
+ times[0] = times[1] = timbuf;
+ if (mflg <= 0)
+ timestruc_to_timeval(&stbuf.st_mtim, times + 1);
+ if (aflg <= 0)
+ timestruc_to_timeval(&stbuf.st_atim, times);
+
+#ifndef S5EMUL
+ /*
+ * Since utime() allows the owner to change file times without
+ * regard to access permission, enforce BSD semantics here
+ * (cannot touch if read-only and not -f).
+ */
+ nowrite = access(filename, R_OK|W_OK);
+ if (nowrite && !force) {
+ (void) fprintf(stderr,
+ "%s: cannot touch %s: no write permission\n",
+ prog, filename);
+ return (-1);
+ }
+#endif /*!S5EMUL*/
+
+ if (utimes(filename, nflg ? NULL : times)) {
+ if (nflg && (errno != EROFS) && (errno != EACCES)) {
+ /*
+ * If utime() failed to set the Present, it
+ * could be a BSD server that is complaining.
+ * If that's the case, try the old read/write trick.
+ */
+ return (oldtouch(filename, &stbuf));
+ }
+ (void) fprintf(stderr,"%s: cannot change times on ", prog);
+ perror(filename);
+ return (-1);
+ }
+ return (0);
+}
+
+int
+oldtouch(filename, statp)
+ char *filename;
+ register struct stat *statp;
+{
+ int rwstatus;
+
+ if ((statp->st_mode & S_IFMT) != S_IFREG) {
+ (void) fprintf(stderr,
+ "%s: %s: only owner may touch special files on this filesystem\n",
+ prog, filename);
+ return (-1);
+ }
+
+#ifndef S5EMUL
+ if (nowrite && force) {
+ if (chmod(filename, 0666)) {
+ fprintf(stderr, "%s: could not chmod ", prog);
+ perror(filename);
+ return (-1);
+ }
+ rwstatus = readwrite(filename, statp->st_size);
+ if (chmod(filename, (int)statp->st_mode)) {
+ fprintf(stderr, "%s: could not chmod back ", prog);
+ perror(filename);
+ return (-1);
+ }
+ return (rwstatus);
+ } else
+#endif /*!S5EMUL*/
+ return (readwrite(filename, statp->st_size));
+}
+
+int
+readwrite(filename, size)
+ char *filename;
+ off_t size;
+{
+ int fd;
+ char first;
+
+ if (size) {
+ if ((fd = open(filename, 2)) < 0)
+ goto error;
+ if (read(fd, &first, 1) != 1)
+ goto closeerror;
+ if (lseek(fd, 0L, 0) == -1)
+ goto closeerror;
+ if (write(fd, &first, 1) != 1)
+ goto closeerror;
+ } else {
+ if ((fd = creat(filename, 0666)) < 0)
+ goto error;
+ }
+ if (close(fd) < 0)
+ goto error;
+ return (0);
+
+closeerror:
+ (void) close(fd);
+error:
+ (void) fprintf(stderr, "%s: could not touch ", prog);
+ perror(filename);
+ return (-1);
+}
+
+#ifdef S5EMUL
+isnumber(s)
+ char *s;
+{
+ register c;
+
+ while (c = *s++)
+ if (!isdigit(c))
+ return (0);
+ return (1);
+}
+#endif S5EMUL
+
+/*
+ * nanoseconds are rounded off to microseconds by flooring.
+ */
+static void
+timestruc_to_timeval(timestruc_t *ts, struct timeval *tv)
+{
+ tv->tv_sec = ts->tv_sec;
+ tv->tv_usec = ts->tv_nsec / 1000;
+}
diff --git a/usr/src/ucbcmd/tr/Makefile b/usr/src/ucbcmd/tr/Makefile
new file mode 100644
index 0000000000..11cb0eacbf
--- /dev/null
+++ b/usr/src/ucbcmd/tr/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= tr
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/tr/tr.c b/usr/src/ucbcmd/tr/tr.c
new file mode 100644
index 0000000000..691837521a
--- /dev/null
+++ b/usr/src/ucbcmd/tr/tr.c
@@ -0,0 +1,178 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+
+/* tr - transliterate data stream */
+int dflag = 0;
+int sflag = 0;
+int cflag = 0;
+int save = 0;
+char code[256];
+char squeez[256];
+char vect[256];
+struct string { int last, max; char *p; } string1, string2;
+
+main(argc,argv)
+char **argv;
+{
+ register i;
+ int j;
+ register c, d;
+ char *compl;
+ int lastd;
+
+ string1.last = string2.last = 0;
+ string1.max = string2.max = 0;
+ string1.p = string2.p = "";
+
+ if(--argc>0) {
+ argv++;
+ if(*argv[0]=='-'&&argv[0][1]!=0) {
+ while(*++argv[0])
+ switch(*argv[0]) {
+ case 'c':
+ cflag++;
+ continue;
+ case 'd':
+ dflag++;
+ continue;
+ case 's':
+ sflag++;
+ continue;
+ }
+ argc--;
+ argv++;
+ }
+ }
+ if(argc>0) string1.p = argv[0];
+ if(argc>1) string2.p = argv[1];
+ for(i=0; i<256; i++)
+ code[i] = vect[i] = 0;
+ if(cflag) {
+ while(c = next(&string1))
+ vect[c&0377] = 1;
+ j = 0;
+ for(i=1; i<256; i++)
+ if(vect[i]==0) vect[j++] = i;
+ vect[j] = 0;
+ compl = vect;
+ }
+ for(i=0; i<256; i++)
+ squeez[i] = 0;
+ lastd = 0;
+ for(;;){
+ if(cflag) c = *compl++;
+ else c = next(&string1);
+ if(c==0) break;
+ d = next(&string2);
+ if(d==0) d = lastd;
+ else lastd = d;
+ squeez[d&0377] = 1;
+ code[c&0377] = dflag?1:d;
+ }
+ while(d = next(&string2))
+ squeez[d&0377] = 1;
+ squeez[0] = 1;
+ for(i=0;i<256;i++) {
+ if(code[i]==0) code[i] = i;
+ else if(dflag) code[i] = 0;
+ }
+
+ clearerr(stdout);
+ while((c=getc(stdin)) != EOF ) {
+ if(c == 0) continue;
+ if(c = code[c&0377]&0377)
+ if(!sflag || c!=save || !squeez[c&0377]) {
+ (void)putchar(save = c);
+ if(ferror(stdout))
+ exit(1);
+ }
+ }
+ exit(0);
+ /* NOTREACHED */
+}
+
+next(s)
+struct string *s;
+{
+
+again:
+ if(s->max) {
+ if(s->last++ < s->max)
+ return(s->last);
+ s->max = s->last = 0;
+ }
+ if(s->last && *s->p=='-') {
+ (void)nextc(s);
+ s->max = nextc(s);
+ if(s->max==0) {
+ s->p--;
+ return('-');
+ }
+ if(s->max < s->last) {
+ s->last = s->max-1;
+ return('-');
+ }
+ goto again;
+ }
+ return(s->last = nextc(s));
+}
+
+nextc(s)
+struct string *s;
+{
+ register c, i, n;
+
+ c = *s->p++;
+ if(c=='\\') {
+ i = n = 0;
+ while(i<3 && (c = *s->p)>='0' && c<='7') {
+ n = n*8 + c - '0';
+ i++;
+ s->p++;
+ }
+ if(i>0) c = n;
+ else c = *s->p++;
+ }
+ if(c==0) *--s->p = 0;
+ return(c&0377);
+}
diff --git a/usr/src/ucbcmd/tset/Makefile b/usr/src/ucbcmd/tset/Makefile
new file mode 100644
index 0000000000..c185245555
--- /dev/null
+++ b/usr/src/ucbcmd/tset/Makefile
@@ -0,0 +1,59 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= tset
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+#LDLIBS += -lcurses
+LDLIBS = -L$(ROOT)/usr/ucblib $(LDLIBS.cmd) -lucb -ltermcap
+
+CPPFLAGS = -I$(ROOT)/usr/ucbinclude $(CPPFLAGS.master)
+
+ROOTSYMLINK= $(ROOTBIN)/reset
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(PROG).c
+ $(SETRUNPATH) $(LINK.c) -o $@ $(PROG).c $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTBIN) $(ROOTPROG) $(ROOTSYMLINK)
+
+$(ROOTSYMLINK):
+ $(RM) $@
+ $(SYMLINK) $(PROG) $@
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/tset/tset.c b/usr/src/ucbcmd/tset/tset.c
new file mode 100644
index 0000000000..4dc67a1975
--- /dev/null
+++ b/usr/src/ucbcmd/tset/tset.c
@@ -0,0 +1,1691 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983 - 1999 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+** TSET -- set terminal modes
+**
+** This program does sophisticated terminal initialization.
+** I recommend that you include it in your .profile or .login
+** file to initialize whatever terminal you are on.
+**
+** There are several features:
+**
+** A special file or sequence (as controlled by the termcap file)
+** is sent to the terminal.
+**
+** Mode bits are set on a per-terminal_type basis (much better
+** than UNIX itself). This allows special delays, automatic
+** tabs, etc.
+**
+** Erase and Kill characters can be set to whatever you want.
+** Default is to change erase to control-H on a terminal which
+** can overstrike, and leave it alone on anything else. Kill
+** is always left alone unless specifically requested. These
+** characters can be represented as "^X" meaning control-X;
+** X is any character.
+**
+** Terminals which are dialups or plugboard types can be aliased
+** to whatever type you may have in your home or office. Thus,
+** if you know that when you dial up you will always be on a
+** TI 733, you can specify that fact to tset. You can represent
+** a type as "?type". This will ask you what type you want it
+** to be -- if you reply with just a newline, it will default
+** to the type given.
+**
+** The current terminal type can be queried.
+**
+** Usage:
+** tset [-] [-EC] [-eC] [-kC] [-iC] [-s] [-h] [-u] [-r]
+** [-m [ident] [test baudrate] :type]
+** [-Q] [-I] [-S] [type]
+**
+** In systems with environments, use:
+** eval `tset -s ...`
+** Actually, this doesn't work in old csh's.
+** Instead, use:
+** tset -s ... > tset.tmp
+** source tset.tmp
+** rm tset.tmp
+** or:
+** set noglob
+** set term=(`tset -S ....`)
+** setenv TERM $term[1]
+** setenv TERMCAP "$term[2]"
+** unset term
+** unset noglob
+**
+** Positional Parameters:
+** type -- the terminal type to force. If this is
+** specified, initialization is for this
+** terminal type.
+**
+** Flags:
+** - -- report terminal type. Whatever type is
+** decided on is reported. If no other flags
+** are stated, the only affect is to write
+** the terminal type on the standard output.
+** -r -- report to user in addition to other flags.
+** -EC -- set the erase character to C on all terminals
+** except those which cannot backspace (e.g.,
+** a TTY 33). C defaults to control-H.
+** -eC -- set the erase character to C on all terminals.
+** C defaults to control-H. If not specified,
+** the erase character is untouched; however, if
+** not specified and the erase character is NULL
+** (zero byte), the erase character is set to CERASE.
+** -kC -- set the kill character to C on all terminals.
+** Default for C is control-U. If not specified,
+** the kill character is untouched; however, if
+** not specified and the kill character is NULL
+** (zero byte), the kill character is set to CKILL.
+** -iC -- set the interrupt character to C on all terminals.
+** Default for C is control-C. If not specified, the
+** interrupt character is untouched; however, if
+** not specified and the interrupt character is NULL
+** (zero byte), the interrupt character is set to
+** control-C.
+** -qC -- reserved for setable quit character.
+** -m -- map the system identified type to some user
+** specified type. The mapping can be baud rate
+** dependent. This replaces the old -d, -p flags.
+** (-d type -> -m dialup:type)
+** (-p type -> -m plug:type)
+** Syntax: -m identifier [test baudrate] :type
+** where: ``identifier'' is terminal type found in
+** /etc/ttys for this port, (abscence of an identifier
+** matches any identifier); ``test'' may be any combination
+** of > = < ! @; ``baudrate'' is as with stty(1);
+** ``type'' is the actual terminal type to use if the
+** mapping condition is met. Multiple maps are scanned
+** in order and the first match prevails.
+** -n -- If the new tty driver from UCB is available, this flag
+** will activate the new options for erase and kill
+** processing. This will be different for printers
+** and crt's. For crts, if the baud rate is < 1200 then
+** erase and kill don't remove characters from the screen.
+** -h -- don't read htmp file. Normally the terminal type
+** is determined by reading the htmp file or the
+** environment (unless some mapping is specified).
+** This forces a read of the ttytype file -- useful
+** when htmp is somehow wrong. (V6 only)
+** -u -- don't update htmp. It seemed like this should
+** be put in. Note that htmp is never actually
+** written if there are no changes, so don't bother
+** bother using this for efficiency reasons alone.
+** -s -- output setenv commands for TERM. This can be
+** used with
+** `tset -s ...`
+** and is to be prefered to:
+** setenv TERM `tset - ...`
+** because -s sets the TERMCAP variable also.
+** -S -- Similar to -s but outputs 2 strings suitable for
+** use in csh .login files as follows:
+** set noglob
+** set term=(`tset -S .....`)
+** setenv TERM $term[1]
+** setenv TERMCAP "$term[2]"
+** unset term
+** unset noglob
+** -Q -- be quiet. don't output 'Erase set to' etc.
+** -I -- don't do terminal initialization (is & if
+** strings).
+** -v -- On virtual terminal systems, don't set up a
+** virtual terminal. Otherwise tset will tell
+** the operating system what kind of terminal you
+** are on (if it is a known terminal) and fix up
+** the output of -s to use virtual terminal sequences.
+**
+** Files:
+** /etc/ttys
+** contains a terminal id -> terminal type
+** mapping; used when any user mapping is specified,
+** or the environment doesn't have TERM set.
+** /etc/termcap
+** a terminal_type -> terminal_capabilities
+** mapping.
+**
+** Return Codes:
+** -1 -- couldn't open termcap.
+** 1 -- bad terminal type, or standard output not tty.
+** 0 -- ok.
+**
+** Defined Constants:
+** DIALUP -- the type code for a dialup port.
+** PLUGBOARD -- the type code for a plugboard port.
+** ARPANET -- the type code for an arpanet port.
+** BACKSPACE -- control-H, the default for -e.
+** CNTL('U') -- control-U, the default for -k.
+** OLDERASE -- the ancient default erase character.
+** FILEDES -- the file descriptor to do the operation
+** on, nominally 1 or 2.
+** STDOUT -- the standard output file descriptor.
+** UIDMASK -- the bit pattern to mask with the getuid()
+** call to get just the user id.
+** GTTYN -- defines file containing generalized ttynames
+** and compiles code to look there.
+**
+** Requires:
+** Routines to handle htmp, ttys, and termcap.
+**
+** Compilation Flags:
+** OLDFLAGS -- must be defined to compile code for any of
+** the -d, -p, or -a flags.
+** OLDDIALUP -- accept the -d flag.
+** OLDPLUGBOARD -- accept the -p flag.
+** OLDARPANET -- accept the -a flag.
+** V6 -- if clear, use environments, not htmp.
+** also use TIOCSETN rather than stty to avoid flushing
+** GTTYN -- if set, compiles code to look at /etc/ttys.
+**
+** Trace Flags:
+** none
+**
+** Diagnostics:
+** Bad flag
+** An incorrect option was specified.
+** Too few args
+** more command line arguments are required.
+** Unexpected arg
+** wrong type of argument was encountered.
+** Cannot open ...
+** The specified file could not be openned.
+** Type ... unknown
+** An unknown terminal type was specified.
+** Cannot update htmp
+** Cannot update htmp file when the standard
+** output is not a terminal.
+** Erase set to ...
+** Telling that the erase character has been
+** set to the specified character.
+** Kill set to ...
+** Ditto for kill
+** Erase is ... Kill is ...
+** Tells that the erase/kill characters were
+** wierd before, but they are being left as-is.
+** Not a terminal
+** Set if FILEDES is not a terminal.
+**
+** Compilation Instructions:
+** cc -n -O tset.c -ltermlib
+** mv a.out tset
+** chown bin tset
+** chmod 4755 tset
+**
+** where 'bin' should be whoever owns the 'htmp' file.
+** If 'htmp' is 666, then tset need not be setuid.
+**
+** For version 6 the compile command should be:
+** cc -n -O -I/usr/include/retrofit tset.c -ltermlib -lretro -lS
+**
+**
+** History:
+** 1/81 -- Added alias checking for mapping identifiers.
+** 7/80 -- '-S' added. '-m' mapping added. TERMCAP string
+** cleaned up.
+** 3/80 -- Changed to use tputs. Prc & flush added.
+** 10/79 -- '-s' option extended to handle TERMCAP
+** variable, set noglob, quote the entry,
+** and know about the Bourne shell. Terminal
+** initialization moved to before any information
+** output so screen clears would not screw you.
+** '-Q' option added.
+** 8/79 -- '-' option alone changed to only output
+** type. '-s' option added. 'VERSION7'
+** changed to 'V6' for compatibility.
+** 12/78 -- modified for eventual migration to VAX/UNIX,
+** so the '-' option is changed to output only
+** the terminal type to STDOUT instead of
+** FILEDES.
+** 9/78 -- '-' and '-p' options added (now fully
+** compatible with ttytype!), and spaces are
+** permitted between the -d and the type.
+** 8/78 -- The sense of -h and -u were reversed, and the
+** -f flag is dropped -- same effect is available
+** by just stating the terminal type.
+** 10/77 -- Written.
+*/
+
+
+#define index strchr
+#define rindex strrchr
+#define curerase modes.c_cc[VERASE]
+#define curkill modes.c_cc[VKILL]
+#define curintr modes.c_cc[VINTR]
+#define olderase oldmodes.c_cc[VERASE]
+#define oldkill oldmodes.c_cc[VKILL]
+#define oldintr oldmodes.c_cc[VINTR]
+
+#include <stdio.h>
+#include <termio.h>
+#include <signal.h>
+
+
+#define YES 1
+#define NO 0
+#undef CNTL
+#define CNTL(c) ((c)&037)
+#define BACKSPACE (CNTL('H'))
+#define isdigit(c) (c >= '0' && c <= '9')
+#define isalnum(c) (c > ' ' && (index("<@=>!:|\177", c) == NULL))
+#define OLDERASE '#'
+
+/* default special characters */
+#ifndef CERASE
+#define CERASE '\177'
+#endif
+#ifndef CKILL
+#define CKILL CNTL('U')
+#endif
+#ifndef CINTR
+#define CINTR CNTL('C')
+#endif
+#ifndef CDSUSP
+#define CQUIT 034 /* FS, ^\ */
+#define CSTART CNTL('Q')
+#define CSTOP CNTL('S')
+#define CEOF CNTL('D')
+#define CEOT CEOF
+#define CBRK 0377
+#define CSUSP CNTL('Z')
+#define CDSUSP CNTL('Y')
+#define CRPRNT CNTL('R')
+#define CFLUSH CNTL('O')
+#define CWERASE CNTL('W')
+#define CLNEXT CNTL('V')
+#endif
+
+#define FILEDES 2 /* do gtty/stty on this descriptor */
+#define STDOUT 1 /* output of -s/-S to this descriptor */
+
+#define UIDMASK -1
+
+#define USAGE "usage: tset [-] [-rsIQS] [-eC] [-kC] [-iC] [-m [ident][test speed]:type] [type]\n"
+
+#define OLDFLAGS
+#define DIALUP "dialup"
+#define OLDDIALUP "sd"
+#define PLUGBOARD "plugboard"
+#define OLDPLUGBOARD "sp"
+/***
+#define ARPANET "arpanet"
+#define OLDARPANET "sa"
+/***/
+
+#define DEFTYPE "unknown"
+
+#define NOTTY 'x'
+
+/*
+ * Baud Rate Conditionals
+ */
+#define ANY 0
+#define GT 1
+#define EQ 2
+#define LT 4
+#define GE (GT|EQ)
+#define LE (LT|EQ)
+#define NE (GT|LT)
+#define ALL (GT|EQ|LT)
+
+
+
+#define NMAP 10
+
+struct map {
+ char *Ident;
+ char Test;
+ char Speed;
+ char *Type;
+} map[NMAP];
+
+struct map *Map = map;
+
+/* This should be available in an include file */
+struct
+{
+ char *string;
+ int speed;
+ int baudrate;
+} speeds[] = {
+ "0", B0, 0,
+ "50", B50, 50,
+ "75", B75, 75,
+ "110", B110, 110,
+ "134", B134, 134,
+ "134.5",B134, 134,
+ "150", B150, 150,
+ "200", B200, 200,
+ "300", B300, 300,
+ "600", B600, 600,
+ "1200", B1200, 1200,
+ "1800", B1800, 1800,
+ "2400", B2400, 2400,
+ "4800", B4800, 4800,
+ "9600", B9600, 9600,
+ "19200",EXTA, 19200,
+ "exta", EXTA, 19200,
+ "extb", EXTB, 38400,
+ "57600",B57600, 57600,
+ "76800",B76800, 76800,
+ "115200",B115200,115200,
+ "153600",B153600,153600,
+ "230400",B230400,230400,
+ "307200",B307200,307200,
+ "460800",B460800,460800,
+ 0,
+};
+
+signed char Erase_char; /* new erase character */
+char Kill_char; /* new kill character */
+char Intr_char; /* new interrupt character */
+char Specialerase; /* set => Erase_char only on terminals with backspace */
+
+char Ttyid = NOTTY; /* terminal identifier */
+char *TtyType; /* type of terminal */
+char *DefType; /* default type if none other computed */
+char *NewType; /* mapping identifier based on old flags */
+int Mapped; /* mapping has been specified */
+int Dash_u; /* don't update htmp */
+int Dash_h; /* don't read htmp */
+int DoSetenv; /* output setenv commands */
+int BeQuiet; /* be quiet */
+int NoInit; /* don't output initialization string */
+int IsReset; /* invoked as reset */
+int Report; /* report current type */
+int Ureport; /* report to user */
+int RepOnly; /* report only */
+int CmndLine; /* output full command lines (-s option) */
+int Ask; /* ask user for termtype */
+int DoVirtTerm = YES; /* Set up a virtual terminal */
+int PadBaud; /* Min rate of padding needed */
+
+#define CAPBUFSIZ 1024
+char Capbuf[CAPBUFSIZ]; /* line from /etc/termcap for this TtyType */
+char *Ttycap; /* termcap line from termcap or environ */
+
+char Aliasbuf[128];
+char *Alias[16];
+
+extern char *strcpy();
+extern char *index();
+
+struct delay
+{
+ int d_delay;
+ int d_bits;
+};
+
+#include "tset.delays.h"
+
+struct termio mode;
+struct termio oldmode;
+struct termios modes;
+struct termios oldmodes;
+int istermios;
+
+char reset(); /* Routine for checking&resetting chars */
+int prc();
+
+main(argc, argv)
+int argc;
+char *argv[];
+{
+ char buf[CAPBUFSIZ];
+ char termbuf[32];
+ auto char *bufp;
+ register char *p;
+ char *command;
+ register int i;
+ int Break;
+ int Not;
+ char *nextarg();
+ char *mapped();
+ extern char *rindex();
+ struct winsize win;
+ extern char *getenv();
+ extern char *tgetstr();
+ char bs_char;
+ int csh;
+ int settle = NO;
+ void setmode();
+ extern char PC;
+ extern short ospeed;
+
+ if ((istermios = ioctl(FILEDES, TCGETS, (char *)&modes)) < 0) {
+ if (ioctl(FILEDES, TCGETA, (char *)&mode) < 0)
+ {
+ prs("Not a terminal\n");
+ exit(1);
+ }
+ bmove((char *)&mode, (char *)&oldmode, sizeof mode);
+ modes.c_lflag = oldmodes.c_lflag = mode.c_lflag;
+ modes.c_oflag = oldmodes.c_oflag = mode.c_oflag;
+ modes.c_iflag = oldmodes.c_iflag = mode.c_iflag;
+ modes.c_cflag = oldmodes.c_cflag = mode.c_cflag;
+ for(i = 0; i < NCC; i++)
+ modes.c_cc[i] = oldmodes.c_cc[i] = mode.c_cc[i];
+ } else
+ bmove((char *)&modes, (char *)&oldmodes, sizeof modes);
+ ospeed = cfgetospeed(&modes);
+ (void) signal(SIGINT, setmode);
+ (void) signal(SIGQUIT, setmode);
+ (void) signal(SIGTERM, setmode);
+
+ if (command = rindex(argv[0], '/'))
+ command++;
+ else
+ command = argv[0];
+ if (sequal(command, "reset") )
+ {
+ /*
+ * Reset the teletype mode bits to a sensible state.
+ * Copied from the program by Kurt Shoens & Mark Horton.
+ * Very useful after crapping out in raw.
+ */
+ if ((istermios = ioctl(FILEDES, TCGETS, (char *)&modes)) < 0) {
+ (void) ioctl(FILEDES, TCGETA, (char *)&mode);
+ modes.c_lflag = mode.c_lflag;
+ modes.c_oflag = mode.c_oflag;
+ modes.c_iflag = mode.c_iflag;
+ modes.c_cflag = mode.c_cflag;
+ for(i = 0; i < NCC; i++)
+ modes.c_cc[i] = mode.c_cc[i];
+ }
+ curerase = reset(curerase, CERASE);
+ curkill = reset(curkill, CKILL);
+ curintr = reset(curintr, CINTR);
+ modes.c_cc[VQUIT] = reset(modes.c_cc[VQUIT], CQUIT);
+ modes.c_cc[VEOF] = reset(modes.c_cc[VEOF], CEOF);
+
+ modes.c_iflag |= (BRKINT|ISTRIP|ICRNL|IXON);
+ modes.c_iflag &= ~(IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF);
+ modes.c_oflag |= (OPOST|ONLCR);
+ modes.c_oflag &= ~(OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL|
+ NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
+ modes.c_cflag |= (CS7|CREAD);
+ modes.c_cflag &= ~(PARODD|CLOCAL);
+ modes.c_lflag |= (ISIG|ICANON|ECHO|ECHOK);
+ modes.c_lflag &= ~(XCASE|ECHONL|NOFLSH);
+ if (istermios < 0) {
+ mode.c_lflag = modes.c_lflag;
+ mode.c_oflag = modes.c_oflag;
+ mode.c_iflag = modes.c_iflag;
+ mode.c_cflag = modes.c_cflag;
+ for(i = 0; i < NCC; i++)
+ mode.c_cc[i] = modes.c_cc[i];
+ (void) ioctl(FILEDES, TCSETAW, (char *)&mode);
+ } else
+ (void) ioctl(FILEDES, TCSETSW, (char *)&modes);
+ Dash_u = YES;
+ BeQuiet = YES;
+ IsReset = YES;
+ }
+ else if (argc == 2 && sequal(argv[1], "-"))
+ {
+ RepOnly = YES;
+ Dash_u = YES;
+ }
+ argc--;
+
+ /* scan argument list and collect flags */
+ while (--argc >= 0)
+ {
+ p = *++argv;
+ if (*p == '-')
+ {
+ if (*++p == NULL)
+ Report = YES; /* report current terminal type */
+ else while (*p) switch (*p++)
+ {
+
+ case 'r': /* report to user */
+ Ureport = YES;
+ continue;
+
+ case 'E': /* special erase: operate on all but TTY33 */
+ Specialerase = YES;
+ /* explicit fall-through to -e case */
+
+ case 'e': /* erase character */
+ if (*p == NULL)
+ Erase_char = -1;
+ else
+ {
+ if (*p == '^' && p[1] != NULL)
+ if (*++p == '?')
+ Erase_char = '\177';
+ else
+ Erase_char = CNTL(*p);
+ else
+ Erase_char = *p;
+ p++;
+ }
+ continue;
+
+ case 'i': /* interrupt character */
+ if (*p == NULL)
+ Intr_char = CNTL('C');
+ else
+ {
+ if (*p == '^' && p[1] != NULL)
+ if (*++p == '?')
+ Intr_char = '\177';
+ else
+ Intr_char = CNTL(*p);
+ else
+ Intr_char = *p;
+ p++;
+ }
+ continue;
+
+ case 'k': /* kill character */
+ if (*p == NULL)
+ Kill_char = CNTL('U');
+ else
+ {
+ if (*p == '^' && p[1] != NULL)
+ if (*++p == '?')
+ Kill_char = '\177';
+ else
+ Kill_char = CNTL(*p);
+ else
+ Kill_char = *p;
+ p++;
+ }
+ continue;
+
+# ifdef OLDFLAGS
+# ifdef OLDDIALUP
+ case 'd': /* dialup type */
+ NewType = DIALUP;
+ goto mapold;
+# endif
+
+# ifdef OLDPLUGBOARD
+ case 'p': /* plugboard type */
+ NewType = PLUGBOARD;
+ goto mapold;
+# endif
+
+# ifdef OLDARPANET
+ case 'a': /* arpanet type */
+ Newtype = ARPANET;
+ goto mapold;
+# endif
+
+mapold: Map->Ident = NewType;
+ Map->Test = ALL;
+ if (*p == NULL)
+ {
+ p = nextarg(argc--, argv++);
+ }
+ Map->Type = p;
+ Map++;
+ Mapped = YES;
+ p = "";
+ continue;
+# endif
+
+ case 'm': /* map identifier to type */
+ /* This code is very loose. Almost no
+ ** syntax checking is done!! However,
+ ** illegal syntax will only produce
+ ** weird results.
+ */
+ if (*p == NULL)
+ {
+ p = nextarg(argc--, argv++);
+ }
+ if (isalnum(*p))
+ {
+ Map->Ident = p; /* identifier */
+ while (isalnum(*p)) p++;
+ }
+ else
+ Map->Ident = "";
+ Break = NO;
+ Not = NO;
+ while (!Break) switch (*p)
+ {
+ case NULL:
+ p = nextarg(argc--, argv++);
+ continue;
+
+ case ':': /* mapped type */
+ *p++ = NULL;
+ Break = YES;
+ continue;
+
+ case '>': /* conditional */
+ Map->Test |= GT;
+ *p++ = NULL;
+ continue;
+
+ case '<': /* conditional */
+ Map->Test |= LT;
+ *p++ = NULL;
+ continue;
+
+ case '=': /* conditional */
+ case '@':
+ Map->Test |= EQ;
+ *p++ = NULL;
+ continue;
+
+ case '!': /* invert conditions */
+ Not = ~Not;
+ *p++ = NULL;
+ continue;
+
+ case 'B': /* Baud rate */
+ p++;
+ /* intentional fallthru */
+ default:
+ if (isdigit(*p) || *p == 'e')
+ {
+ Map->Speed = baudrate(p);
+ while (isalnum(*p) || *p == '.')
+ p++;
+ }
+ else
+ Break = YES;
+ continue;
+ }
+ if (Not) /* invert sense of test */
+ {
+ Map->Test = (~(Map->Test))&ALL;
+ }
+ if (*p == NULL)
+ {
+ p = nextarg(argc--, argv++);
+ }
+ Map->Type = p;
+ p = "";
+ Map++;
+ Mapped = YES;
+ continue;
+
+ case 'h': /* don't get type from htmp or env */
+ Dash_h = YES;
+ continue;
+
+ case 'u': /* don't update htmp */
+ Dash_u = YES;
+ continue;
+
+ case 's': /* output setenv commands */
+ DoSetenv = YES;
+ CmndLine = YES;
+ continue;
+
+ case 'S': /* output setenv strings */
+ DoSetenv = YES;
+ CmndLine = NO;
+ continue;
+
+ case 'Q': /* be quiet */
+ BeQuiet = YES;
+ continue;
+
+ case 'I': /* no initialization */
+ NoInit = YES;
+ continue;
+
+ case 'A': /* Ask user */
+ Ask = YES;
+ continue;
+
+ case 'v': /* no virtual terminal */
+ DoVirtTerm = NO;
+ continue;
+
+ default:
+ *p-- = NULL;
+ fatal("Bad flag -", p);
+ }
+ }
+ else
+ {
+ /* terminal type */
+ DefType = p;
+ }
+ }
+
+ if (DefType)
+ {
+ if (Mapped)
+ {
+ Map->Ident = ""; /* means "map any type" */
+ Map->Test = ALL; /* at all baud rates */
+ Map->Type = DefType; /* to the default type */
+ }
+ else
+ TtyType = DefType;
+ }
+
+ /*
+ * Get rid of $TERMCAP, if it's there, so we get a real
+ * entry from /etc/termcap. This prevents us from being
+ * fooled by out of date stuff in the environment, and
+ * makes tabs work right on CB/Unix.
+ */
+ bufp = getenv("TERMCAP");
+ if (bufp && *bufp != '/')
+ (void) strcpy(bufp-8, "NOTHING"); /* overwrite only "TERMCAP" */
+ /* get current idea of terminal type from environment */
+ if (!Dash_h && TtyType == 0)
+ TtyType = getenv("TERM");
+
+ if (!RepOnly && Ttyid == NOTTY && (TtyType == 0 || !Dash_h))
+ Ttyid = ttyname(FILEDES);
+
+ /* If still undefined, use DEFTYPE */
+ if (TtyType == 0)
+ {
+ TtyType = DEFTYPE;
+ }
+
+ /* check for dialup or other mapping */
+ if (Mapped)
+ {
+ if (!(Alias[0] && isalias(TtyType)))
+ if (tgetent(Capbuf, TtyType) > 0)
+ makealias(Capbuf);
+ TtyType = mapped(TtyType);
+ }
+
+ /* TtyType now contains a pointer to the type of the terminal */
+ /* If the first character is '?', ask the user */
+ if (TtyType[0] == '?')
+ {
+ Ask = YES;
+ TtyType++;
+ if (TtyType[0] == '\0')
+ TtyType = DEFTYPE;
+ }
+ if (Ask)
+ {
+ask:
+ prs("TERM = (");
+ prs(TtyType);
+ prs(") ");
+ flush();
+
+ /* read the terminal. If not empty, set type */
+ i = read(2, termbuf, sizeof termbuf - 1);
+ if (i > 0)
+ {
+ if (termbuf[i - 1] == '\n')
+ i--;
+ termbuf[i] = '\0';
+ if (termbuf[0] != '\0')
+ TtyType = termbuf;
+ }
+ }
+
+ /* get terminal capabilities */
+ if (!(Alias[0] && isalias(TtyType))) {
+ switch (tgetent(Capbuf, TtyType))
+ {
+ case -1:
+ prs("Cannot find termcap\n");
+ flush();
+ exit(-1);
+
+ case 0:
+ prs("Type ");
+ prs(TtyType);
+ prs(" unknown\n");
+ flush();
+ if (DoSetenv)
+ {
+ TtyType = DEFTYPE;
+ Alias[0] = '\0';
+ goto ask;
+ }
+ else
+ exit(1);
+ }
+ }
+ Ttycap = Capbuf;
+
+ if (!RepOnly)
+ {
+ /* determine erase and kill characters */
+ if (Specialerase && !tgetflag("bs"))
+ Erase_char = 0;
+ bufp = buf;
+ p = tgetstr("kb", &bufp);
+ if (p == NULL || p[1] != '\0')
+ p = tgetstr("bc", &bufp);
+ if (p != NULL && p[1] == '\0')
+ bs_char = p[0];
+ else if (tgetflag("bs"))
+ bs_char = BACKSPACE;
+ else
+ bs_char = 0;
+ /*
+ * The next statement can't be fixed, because now users
+ * depend on keeping their erase character as DEL if the
+ * system set it there. People who want backspace have
+ * to say tset -e.
+ */
+ if (Erase_char == 0 && !tgetflag("os") && curerase == OLDERASE)
+ {
+ if (tgetflag("bs") || bs_char != 0)
+ Erase_char = -1;
+ }
+ if (Erase_char < 0)
+ Erase_char = (bs_char != 0) ? bs_char : BACKSPACE;
+
+ if (curerase == 0)
+ curerase = CERASE;
+ if (Erase_char != 0)
+ curerase = Erase_char;
+
+ if (curintr == 0)
+ curintr = CINTR;
+ if (Intr_char != 0)
+ curintr = Intr_char;
+
+ if (curkill == 0)
+ curkill = CKILL;
+ if (Kill_char != 0)
+ curkill = Kill_char;
+
+ /* set modes */
+ PadBaud = tgetnum("pb"); /* OK if fails */
+ for (i=0; speeds[i].string; i++)
+ if (speeds[i].baudrate == PadBaud) {
+ PadBaud = speeds[i].speed;
+ break;
+ }
+ setdelay("dC", CRdelay, CRbits, &modes.c_oflag);
+ setdelay("dN", NLdelay, NLbits, &modes.c_oflag);
+ setdelay("dB", BSdelay, BSbits, &modes.c_oflag);
+ setdelay("dF", FFdelay, FFbits, &modes.c_oflag);
+ setdelay("dT", TBdelay, TBbits, &modes.c_oflag);
+ setdelay("dV", VTdelay, VTbits, &modes.c_oflag);
+
+ if (tgetflag("UC") || (command[0] & 0140) == 0100) {
+ modes.c_iflag |= IUCLC;
+ modes.c_oflag |= OLCUC;
+ modes.c_cflag |= XCASE;
+ }
+ else if (tgetflag("LC")) {
+ modes.c_iflag &= ~IUCLC;
+ modes.c_oflag &= ~OLCUC;
+ modes.c_cflag &= ~XCASE;
+ }
+ modes.c_iflag &= ~(PARMRK|INPCK);
+ modes.c_lflag |= ICANON;
+ if (tgetflag("EP")) {
+ modes.c_iflag |= INPCK;
+ modes.c_cflag |= PARENB;
+ modes.c_cflag &= ~PARODD;
+ }
+ if (tgetflag("OP")) {
+ modes.c_iflag |= INPCK;
+ modes.c_cflag |= PARENB;
+ modes.c_cflag |= PARODD;
+ }
+
+ modes.c_oflag |= ONLCR;
+ modes.c_iflag |= ICRNL;
+ modes.c_lflag |= ECHO;
+ modes.c_oflag |= TAB3;
+ if (tgetflag("NL")) { /* new line, not line feed */
+ modes.c_oflag &= ~ONLCR;
+ modes.c_iflag &= ~ICRNL;
+ }
+ if (tgetflag("HD")) /* half duplex */
+ modes.c_lflag &= ~ECHO;
+ if (tgetflag("pt")) /* print tabs */
+ modes.c_oflag &= ~TAB3;
+
+ modes.c_lflag |= (ECHOE|ECHOK);
+ if (tgetflag("hc"))
+ { /** set printer modes **/
+ modes.c_lflag &= ~ECHOE;
+ }
+
+ /* get pad character */
+ bufp = buf;
+ if (tgetstr("pc", &bufp) != 0)
+ PC = buf[0];
+
+ /* output startup string */
+ if (!NoInit)
+ {
+ if (oldmodes.c_oflag&(TAB3|ONLCR|OCRNL|ONLRET))
+ {
+ oldmodes.c_oflag &= (TAB3|ONLCR|OCRNL|ONLRET);
+ setmode(-1);
+ }
+ if (settabs()) {
+ settle = YES;
+ flush();
+ }
+ bufp = buf;
+ if (IsReset && tgetstr("rs", &bufp) != 0 ||
+ tgetstr("is", &bufp) != 0)
+ {
+ tputs(buf, 0, prc);
+ settle = YES;
+ flush();
+ }
+ bufp = buf;
+ if (IsReset && tgetstr("rf", &bufp) != 0 ||
+ tgetstr("if", &bufp) != 0)
+ {
+ cat(buf);
+ settle = YES;
+ }
+ if (settle)
+ {
+ prc('\r');
+ if (IsReset)
+ prc('\n'); /* newline too */
+ flush();
+ sleep(1); /* let terminal settle down */
+ }
+ }
+
+ setmode(0); /* set new modes, if they've changed */
+
+ /* set up environment for the shell we are using */
+ /* (this code is rather heuristic, checking for $SHELL */
+ /* ending in the 3 characters "csh") */
+ csh = NO;
+ if (DoSetenv)
+ {
+ char *sh;
+
+ if ((sh = getenv("SHELL")) && (i = strlen(sh)) >= 3)
+ {
+ if ((csh = sequal(&sh[i-3], "csh")) && CmndLine)
+ (void) write(STDOUT, "set noglob;\n", 12);
+ }
+ if (!csh)
+ /* running Bourne shell */
+ (void) write(STDOUT, "export TERMCAP TERM;\n", 21);
+ }
+ }
+
+ /* report type if appropriate */
+ if (DoSetenv || Report || Ureport)
+ {
+ /* if type is the short name, find first alias (if any) */
+ makealias(Ttycap);
+ if (sequal(TtyType, Alias[0]) && Alias[1]) {
+ TtyType = Alias[1];
+ }
+
+ if (DoSetenv)
+ {
+ if (csh)
+ {
+ if (CmndLine)
+ (void) write(STDOUT, "setenv TERM ", 12);
+ (void) write(STDOUT, TtyType, strlen(TtyType));
+ (void) write(STDOUT, " ", 1);
+ if (CmndLine)
+ (void) write(STDOUT, ";\n", 2);
+ }
+ else
+ {
+ (void) write(STDOUT, "TERM=", 5);
+ (void) write(STDOUT, TtyType, strlen(TtyType));
+ (void) write(STDOUT, ";\n", 2);
+ }
+ }
+ else if (Report)
+ {
+ (void) write(STDOUT, TtyType, strlen(TtyType));
+ (void) write(STDOUT, "\n", 1);
+ }
+ if (Ureport)
+ {
+ prs("Terminal type is ");
+ prs(TtyType);
+ prs("\n");
+ flush();
+ }
+
+ if (DoSetenv)
+ {
+ if (csh)
+ {
+ if (CmndLine)
+ (void) write(STDOUT, "setenv TERMCAP '", 16);
+ }
+ else
+ (void) write(STDOUT, "TERMCAP='", 9);
+ wrtermcap(Ttycap);
+ if (csh)
+ {
+ if (CmndLine)
+ {
+ (void) write(STDOUT, "';\n", 3);
+ (void) write(STDOUT, "unset noglob;\n", 14);
+ }
+ }
+ else
+ (void) write(STDOUT, "';\n", 3);
+ }
+ }
+
+ if (RepOnly)
+ exit(0);
+
+ /* tell about changing erase, kill and interrupt characters */
+ reportek("Erase", curerase, olderase, CERASE);
+ reportek("Kill", curkill, oldkill, CKILL);
+ reportek("Interrupt", curintr, oldintr, CINTR);
+
+ exit(0);
+}
+
+/*
+ * Set the hardware tabs on the terminal, using the ct (clear all tabs),
+ * st (set one tab) and ch (horizontal cursor addressing) capabilities.
+ * This is done before if and is, so they can patch in case we blow this.
+ */
+settabs()
+{
+ char caps[100];
+ char *capsp = caps;
+ char *clear_tabs, *set_tab, *set_column, *set_pos;
+ char *tg_out, *tgoto();
+ int c;
+ extern char *tgetstr();
+ int lines, columns;
+
+ clear_tabs = tgetstr("ct", &capsp);
+ set_tab = tgetstr("st", &capsp);
+ set_column = tgetstr("ch", &capsp);
+ if (set_column == 0)
+ set_pos = tgetstr("cm", &capsp);
+
+ if (clear_tabs && set_tab) {
+ prc('\r'); /* force to be at left margin */
+ tputs(clear_tabs, 0, prc);
+ }
+ if (set_tab) {
+ columns = tgetnum("co");
+ lines = tgetnum("li");
+ for (c=0; c<columns; c += 8) {
+ /* get to that column. */
+ tg_out = "OOPS"; /* also returned by tgoto */
+ if (set_column)
+ tg_out = tgoto(set_column, 0, c);
+ if (*tg_out == 'O' && set_pos)
+ tg_out = tgoto(set_pos, c, lines-1);
+ if (*tg_out != 'O')
+ tputs(tg_out, 1, prc);
+ else if (c != 0) {
+ prc(' '); prc(' '); prc(' '); prc(' ');
+ prc(' '); prc(' '); prc(' '); prc(' ');
+ }
+ /* set the tab */
+ tputs(set_tab, 0, prc);
+ }
+ prc('\r');
+ return 1;
+ }
+ return 0;
+}
+
+void setmode(flag)
+int flag;
+/* flag serves several purposes:
+ * if called as the result of a signal, flag will be > 0.
+ * if called from terminal init, flag == -1 means reset "oldmode".
+ * called with flag == 0 at end of normal mode processing.
+ */
+{
+ struct termio *ttymode;
+ struct termios *ttymodes;
+ register int i;
+
+ ttymode = (struct termio *)0;
+ ttymodes = (struct termios *)0;
+
+ if (flag < 0) { /* unconditionally reset oldmode (called from init) */
+ if (istermios < 0) {
+ oldmode.c_lflag = oldmodes.c_lflag;
+ oldmode.c_oflag = oldmodes.c_oflag;
+ oldmode.c_iflag = oldmodes.c_iflag;
+ oldmode.c_cflag = oldmodes.c_cflag;
+ for(i = 0; i < NCC; i++)
+ oldmode.c_cc[i] = oldmodes.c_cc[i];
+ ttymode = &oldmode;
+ } else
+ ttymodes = &oldmodes;
+ } else {
+ if (istermios < 0) {
+ oldmode.c_lflag = oldmodes.c_lflag;
+ oldmode.c_oflag = oldmodes.c_oflag;
+ oldmode.c_iflag = oldmodes.c_iflag;
+ oldmode.c_cflag = oldmodes.c_cflag;
+ for(i = 0; i < NCC; i++)
+ oldmode.c_cc[i] = oldmodes.c_cc[i];
+ mode.c_lflag = modes.c_lflag;
+ mode.c_oflag = modes.c_oflag;
+ mode.c_iflag = modes.c_iflag;
+ mode.c_cflag = modes.c_cflag;
+ for(i = 0; i < NCC; i++)
+ mode.c_cc[i] = modes.c_cc[i];
+ if (!bequal((char *)&mode, (char *)&oldmode, sizeof mode))
+ ttymode = &mode;
+ } else if (!bequal((char *)&modes, (char *)&oldmodes,
+ sizeof modes))
+ ttymodes = &modes;
+ }
+
+ if (ttymode)
+ {
+ (void) ioctl(FILEDES, TCSETAW, (char *)ttymode);
+ } else if (ttymodes) {
+ (void) ioctl(FILEDES, TCSETSW, (char *)ttymodes);
+ }
+ if (flag > 0) /* trapped signal */
+ exit(1);
+}
+
+reportek(name, new, old, def)
+char *name;
+char old;
+char new;
+char def;
+{
+ register char o;
+ register char n;
+ register char *p;
+ char buf[32];
+ char *bufp;
+ extern char *tgetstr();
+
+ if (BeQuiet)
+ return;
+ o = old;
+ n = new;
+
+ if (o == n && n == def)
+ return;
+ prs(name);
+ if (o == n)
+ prs(" is ");
+ else
+ prs(" set to ");
+ bufp = buf;
+ if (tgetstr("kb", &bufp) > (char *)0 && n == buf[0] && buf[1] == NULL)
+ prs("Backspace\n");
+ else if (n == 0177)
+ prs("Delete\n");
+ else
+ {
+ if (n < 040)
+ {
+ prs("Ctrl-");
+ n ^= 0100;
+ }
+ p = "x\n";
+ p[0] = n;
+ prs(p);
+ }
+ flush();
+}
+
+
+
+
+setdelay(cap, dtab, bits, flags)
+char *cap;
+struct delay dtab[];
+int bits;
+short *flags;
+{
+ register int i;
+ register struct delay *p;
+ extern short ospeed;
+
+ /* see if this capability exists at all */
+ i = tgetnum(cap);
+ if (i < 0)
+ i = 0;
+ /* No padding at speeds below PadBaud */
+ if (PadBaud > ospeed)
+ i = 0;
+
+ /* clear out the bits, replace with new ones */
+ *flags &= ~bits;
+
+ /* scan dtab for first entry with adequate delay */
+ for (p = dtab; p->d_delay >= 0; p++)
+ {
+ if (p->d_delay >= i)
+ {
+ p++;
+ break;
+ }
+ }
+
+ /* use last entry if none will do */
+ *flags |= (--p)->d_bits;
+}
+
+
+prs(s)
+char *s;
+{
+ while (*s != '\0')
+ prc(*s++);
+}
+
+
+char OutBuf[256];
+int OutPtr;
+
+prc(c)
+char c;
+{
+ OutBuf[OutPtr++] = c;
+ if (OutPtr >= sizeof OutBuf)
+ flush();
+}
+
+flush()
+{
+ if (OutPtr > 0)
+ (void) write(2, OutBuf, OutPtr);
+ OutPtr = 0;
+}
+
+
+cat(file)
+char *file;
+{
+ register int fd;
+ register int i;
+ char buf[BUFSIZ];
+
+ fd = open(file, 0);
+ if (fd < 0)
+ {
+ prs("Cannot open ");
+ prs(file);
+ prs("\n");
+ flush();
+ return;
+ }
+
+ while ((i = read(fd, buf, BUFSIZ)) > 0)
+ (void) write(FILEDES, buf, i);
+
+ (void) close(fd);
+}
+
+
+
+bmove(from, to, length)
+char *from;
+char *to;
+int length;
+{
+ register char *p, *q;
+ register int i;
+
+ i = length;
+ p = from;
+ q = to;
+
+ while (i-- > 0)
+ *q++ = *p++;
+}
+
+
+
+bequal(a, b, len) /* must be same thru len chars */
+char *a;
+char *b;
+int len;
+{
+ register char *p, *q;
+ register int i;
+
+ i = len;
+ p = a;
+ q = b;
+
+ while ((*p == *q) && --i > 0)
+ {
+ p++; q++;
+ }
+ return ((*p == *q) && i >= 0);
+}
+
+sequal(a, b) /* must be same thru NULL */
+char *a;
+char *b;
+{
+ register char *p = a, *q = b;
+
+ while (*p && *q && (*p == *q))
+ {
+ p++; q++;
+ }
+ return (*p == *q);
+}
+
+makealias(buf)
+char *buf;
+{
+ register int i;
+ register char *a;
+ register char *b;
+
+ Alias[0] = a = Aliasbuf;
+ b = buf;
+ i = 1;
+ while (*b && *b != ':') {
+ if (*b == '|') {
+ *a++ = NULL;
+ Alias[i++] = a;
+ b++;
+ }
+ else
+ *a++ = *b++;
+ }
+ *a = NULL;
+ Alias[i] = NULL;
+# ifdef DEB
+ for(i = 0; Alias[i]; printf("A:%s\n", Alias[i++]));
+# endif
+}
+
+isalias(ident) /* is ident same as one of the aliases? */
+char *ident;
+{
+ char **a = Alias;
+
+ if (*a)
+ while (*a)
+ if (sequal(ident, *a))
+ return(YES);
+ else
+ a++;
+ return(NO);
+}
+
+
+/*
+ * routine to output the string for the environment TERMCAP variable
+ */
+#define WHITE(c) (c == ' ' || c == '\t')
+char delcap[128][2];
+int ncap = 0;
+
+wrtermcap(bp)
+char *bp;
+{
+ char buf[CAPBUFSIZ];
+ char *p = buf;
+ char *tp;
+ char *putbuf();
+ int space, empty;
+
+ /* discard names with blanks */
+/** May not be desireable ? **/
+ while (*bp && *bp != ':') {
+ if (*bp == '|') {
+ tp = bp+1;
+ space = NO;
+ while (*tp && *tp != '|' && *tp != ':') {
+ space = (space || WHITE(*tp) );
+ tp++;
+ }
+ if (space) {
+ bp = tp;
+ continue;
+ }
+ }
+ *p++ = *bp++;
+ }
+/**/
+
+ while (*bp) {
+ switch (*bp) {
+ case ':': /* discard empty, cancelled or dupl fields */
+ tp = bp+1;
+ empty = YES;
+ while (*tp && *tp != ':') {
+ empty = (empty && WHITE(*tp) );
+ tp++;
+ }
+ if (empty || cancelled(bp+1)) {
+ bp = tp;
+ continue;
+ }
+ break;
+
+ case ' ': /* no spaces in output */
+ p = putbuf(p, "\\040");
+ bp++;
+ continue;
+
+ case '!': /* the shell thinks this is history */
+ p = putbuf(p, "\\041");
+ bp++;
+ continue;
+
+ case ',': /* the shell thinks this is history */
+ p = putbuf(p, "\\054");
+ bp++;
+ continue;
+
+ case '"': /* no quotes in output */
+ p = putbuf(p, "\\042");
+ bp++;
+ continue;
+
+ case '\'': /* no quotes in output */
+ p = putbuf(p, "\\047");
+ bp++;
+ continue;
+
+ case '`': /* no back quotes in output */
+ p = putbuf(p, "\\140");
+ bp++;
+ continue;
+
+ case '\\':
+ case '^': /* anything following is OK */
+ *p++ = *bp++;
+ }
+ *p++ = *bp++;
+ }
+ *p++ = ':'; /* we skipped the last : with the : lookahead hack */
+ (void) write (STDOUT, buf, p-buf);
+}
+
+cancelled(cap)
+char *cap;
+{
+ register int i;
+
+ for (i = 0; i < ncap; i++)
+ {
+ if (cap[0] == delcap[i][0] && cap[1] == delcap[i][1])
+ return (YES);
+ }
+ /* delete a second occurrance of the same capability */
+ delcap[ncap][0] = cap[0];
+ delcap[ncap][1] = cap[1];
+ ncap++;
+ return (cap[2] == '@');
+}
+
+char *
+putbuf(ptr, str)
+char *ptr;
+char *str;
+{
+ char buf[20];
+
+ while (*str) {
+ switch (*str) {
+ case '\033':
+ ptr = putbuf(ptr, "\\E");
+ str++;
+ break;
+ default:
+ if (*str <= ' ') {
+ (void) sprintf(buf, "\\%03o", *str);
+ ptr = putbuf(ptr, buf);
+ str++;
+ } else
+ *ptr++ = *str++;
+ }
+ }
+ return (ptr);
+}
+
+
+baudrate(p)
+char *p;
+{
+ char buf[8];
+ int i = 0;
+
+ while (i < 7 && (isalnum(*p) || *p == '.'))
+ buf[i++] = *p++;
+ buf[i] = NULL;
+ for (i=0; speeds[i].string; i++)
+ if (sequal(speeds[i].string, buf))
+ return (speeds[i].speed);
+ return (-1);
+}
+
+char *
+mapped(type)
+char *type;
+{
+ extern short ospeed;
+ int match;
+
+# ifdef DEB
+ printf ("spd:%d\n", ospeed);
+ prmap();
+# endif
+ Map = map;
+ while (Map->Ident)
+ {
+ if (*(Map->Ident) == NULL || sequal(Map->Ident, type) || isalias(Map->Ident))
+ {
+ match = NO;
+ switch (Map->Test)
+ {
+ case ANY: /* no test specified */
+ case ALL:
+ match = YES;
+ break;
+
+ case GT:
+ match = (ospeed > Map->Speed);
+ break;
+
+ case GE:
+ match = (ospeed >= Map->Speed);
+ break;
+
+ case EQ:
+ match = (ospeed == Map->Speed);
+ break;
+
+ case LE:
+ match = (ospeed <= Map->Speed);
+ break;
+
+ case LT:
+ match = (ospeed < Map->Speed);
+ break;
+
+ case NE:
+ match = (ospeed != Map->Speed);
+ break;
+ }
+ if (match)
+ return (Map->Type);
+ }
+ Map++;
+ }
+ /* no match found; return given type */
+ return (type);
+}
+
+# ifdef DEB
+prmap()
+{
+ Map = map;
+ while (Map->Ident)
+ {
+ printf ("%s t:%d s:%d %s\n",
+ Map->Ident, Map->Test, Map->Speed, Map->Type);
+ Map++;
+ }
+}
+# endif
+
+char *
+nextarg(argc, argv)
+int argc;
+char *argv[];
+{
+ if (argc <= 0)
+ fatal ("Too few args: ", *argv);
+ if (*(*++argv) == '-')
+ fatal ("Unexpected arg: ", *argv);
+ return (*argv);
+}
+
+fatal (mesg, obj)
+char *mesg;
+char *obj;
+{
+ prs (mesg);
+ prs (obj);
+ prc ('\n');
+ prs (USAGE);
+ flush();
+ exit(1);
+}
+
+
+/*
+ * Stolen from /usr/src/ucb/reset.c, which this mod obsoletes.
+ */
+char
+reset(ch, def)
+ char ch;
+ int def;
+{
+
+ if (ch == 0 || (ch&0377) == 0377)
+ return def;
+ return ch;
+}
diff --git a/usr/src/ucbcmd/tset/tset.delays.h b/usr/src/ucbcmd/tset/tset.delays.h
new file mode 100644
index 0000000000..46044007a5
--- /dev/null
+++ b/usr/src/ucbcmd/tset/tset.delays.h
@@ -0,0 +1,110 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+** SYSTEM DEPENDENT TERMINAL DELAY TABLES
+**
+**
+** This file maintains the correspondence between the delays
+** defined in /etc/termcap and the delay algorithms on a
+** particular system. For each type of delay, the bits used
+** for that delay must be specified (in XXbits) and a table
+** must be defined giving correspondences between delays and
+** algorithms. Algorithms which are not fixed delays (such
+** as dependent on current column or line number) must be
+** cludged in some way at this time.
+*/
+
+
+
+/*
+** Carriage Return delays
+*/
+
+int CRbits = CRDLY;
+struct delay CRdelay[] =
+{
+ 0, CR0,
+ 9, CR3,
+ 80, CR1,
+ 160, CR2,
+ -1
+};
+
+/*
+** New Line delays
+*/
+
+int NLbits = NLDLY;
+struct delay NLdelay[] =
+{
+ 0, NL0,
+ 66, NL1, /* special M37 delay */
+ -1
+};
+
+
+/*
+** Back Space delays
+*/
+
+int BSbits = BSDLY;
+struct delay BSdelay[] =
+{
+ 0, BS0,
+ -1
+};
+
+
+/*
+** TaB delays
+*/
+
+int TBbits = TABDLY;
+struct delay TBdelay[] =
+{
+ 0, TAB0,
+ 11, TAB1, /* special M37 delay */
+ -1
+};
+
+
+/*
+** Form Feed delays
+*/
+
+int FFbits = FFDLY;
+struct delay FFdelay[] =
+{
+ 0, FF0,
+ 2000, FF1,
+ -1
+};
+
+
+/*
+** Vertical Tab delays
+*/
+
+int VTbits = VTDLY;
+struct delay VTdelay[] =
+{
+ 0, VT0,
+ 2000, VT1,
+ -1
+};
+
diff --git a/usr/src/ucbcmd/ucblinks/Makefile b/usr/src/ucbcmd/ucblinks/Makefile
new file mode 100644
index 0000000000..57938b8f64
--- /dev/null
+++ b/usr/src/ucbcmd/ucblinks/Makefile
@@ -0,0 +1,63 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright (c) 1998,2001 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+#ident "%Z%%M% %I% %E% SMI"
+
+PROG= ucblinks
+OBJS= $(PROG).o
+
+SHLIBEXFILES= ucblinks.sh
+SHLIBFILES= ucblinks.awk
+
+include ../Makefile.ucbcmd
+
+ROOTLIBEXFILES= $(ROOTLIB)/$(SHLIBEXFILES)
+ROOTLIBFILES= $(ROOTLIB)/$(SHLIBFILES)
+GROUP = sys
+$(ROOTLIBEXFILES) := FILEMODE = 555
+$(ROOTLIBFILES) := FILEMODE = 644
+$(ROOTLIB) := GROUP = bin
+$(PROG) := GROUP = bin
+
+LDLIBS += -ldevinfo
+
+CLEANFILES += $(OBJS)
+
+
+.KEEP_STATE:
+
+all: $(PROG) $(SHLIBEXFILES) $(SHLIBFILES)
+
+install: all $(ROOTPROG) $(ROOTLIB) $(ROOTLIBEXFILES) $(ROOTLIBFILES)
+
+$(ROOTLIB):
+ $(INS.dir)
+
+clean:
+ $(RM) $(CLEANFILES)
+
+lint:
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/ucblinks/ucblinks.awk b/usr/src/ucbcmd/ucblinks/ucblinks.awk
new file mode 100644
index 0000000000..fa54ea99f3
--- /dev/null
+++ b/usr/src/ucbcmd/ucblinks/ucblinks.awk
@@ -0,0 +1,214 @@
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# This awk-script is the rule-base used in previous release for creating
+# compatibility-mode names.
+#
+# WARNING: these rules are no longer used by default. ucblinks
+# is now a binary, not a script. This rule-base can still
+# be used, however, by running ucblinks with the option
+# "-e /usr/ucblib/ucblinks.awk". See the ucblinks(1B) man
+# page for more information.
+#
+# The idea is to create the names as symbolic links to their SunOS5
+# counterparts by preference. If no counterpart exists a direct link to the
+# devfs "/devices" directory is made.
+#
+# It does this base on input of the existing devices in the system.
+# The format of the input file is:
+#
+# driver-name \t minor number \t [b|c] \t /devices-name \t first-minor-component
+#
+# That is,
+#
+# $1 driver-name
+# $2 minor number
+# $3 b(lock) or c(haracter) device
+# $4 devices-directory name; relative to /dev (../devices/xxx)
+# $5 first minor component name (string between ':' and nextr ','
+# in last path-component of the /devices-name)
+#
+# and these are referred to throughout the script.
+#
+# The output of the script-rules are lines of the form:
+#
+# devname["device-link-fullname"] = "compatname";
+# devdir["device-link-fullname"] = "compatdir";
+#
+# The device-link-fullname should be relative to the directory in which the
+# SunOS5 link is expected to be found. 'compatdir' is that directory name,
+# FOLLOWED BY A SLASH. 'compatname' is the compatability name that should be
+# generated.
+#
+
+#---------------------------------------------------------------------------
+# DATABASE: Only modify below this line!
+#
+#
+#
+# The following devices need no changes, since the 4.x and 5.x names
+# are the same:
+#
+# console tty mem kmem null zero drum mouse klog kbd dump tcp udp
+# mbmem mbio
+#
+# nit vd eeprom openprom des pp* vp* vpc*
+
+$3 == "b" && $1 == "fd" {
+ if ($5 == "c")
+ out(sprintf("%s%d%s", $1, $2/8, $5), "./",
+ sprintf("%s%d", $1, $2/8));
+ else
+ out(sprintf("%s%d%s", $1, $2/8, $5), "./");
+ }
+$3 == "c" && $1 == "fd" {
+ if ($5 == "c")
+ out(sprintf("r%s%d%s", $1, $2/8, $5), "./",
+ sprintf("r%s%d", $1, $2/8));
+ else
+ out(sprintf("r%s%d%s", $1, $2/8, $5), "./");
+ }
+
+
+#
+# Standard disks (all bar IPI)
+#
+# Note special 'cddev' array test to make sure device is not a CD device
+# in the case of a SCSI disk
+#
+$3 == "b" && (($1 == "sd" && !cddev[$4]) || $1 == "xd" || $1 == "xy") {
+ if ($2 < 8)
+ out(sprintf("%s%d%s", $1, 3, $5), "dsk/");
+ else if ($2 >= 24 && $2 < 32)
+ out(sprintf("%s%d%s", $1, 0, $5), "dsk/");
+ else
+ out(sprintf("%s%d%s", $1, $2/8, $5), "dsk/");
+ }
+$3 == "c" && (($1 == "sd" && !cddev[$4]) || $1 == "xd" || $1 == "xy") {
+ if ($2 < 8)
+ out(sprintf("r%s%d%s", $1, 3, $5), "rdsk/");
+ else if ($2 >= 24 && $2 < 32)
+ out(sprintf("r%s%d%s", $1, 0, $5), "rdsk/");
+ else
+ out(sprintf("r%s%d%s", $1, $2/8, $5), "rdsk/");
+ }
+#
+# SCSI CD drive
+#
+$1 == "sd" && cddev[$4] && $5 == "c" {
+ if (cdnum[$2] "" == "") cdnum[$2] = cdno++;
+ if ($3 == "c") pfx = "r"; else pfx = "";
+ out(pfx "sr" cdnum[$2], pfx "dsk/");
+ }
+#
+# Next assumes IPI unit number entirely within minor
+# (that is, 5.0 numbering rather than 4.1 numbering)
+#
+$3 == "b" && $1 == "id" {
+ out(sprintf("id%x%s", $2, $5), "dsk/");
+ }
+$3 == "c" && $1 == "id" {
+ out(sprintf("rid%x%s", $2, $5), "rdsk/");
+ }
+#
+# Tape drives
+#
+# SCSI and XT Tape Drives
+#
+($1 == "st" || $1 == "xt") && NF == 5 && $5 !~ /^[bn]/ {
+ if (($2 % 128) < 64) break; # Not BSD-flavour
+ drive = ($2%4) + ((int($2/128)%32) * 4);
+ den = int($2/8) % 4;
+ if ($1 == "xt") $1 == "mt"; # xt drives appear as mt devices
+ if ($5 ~ /n$/) pfx = "nr"; else pfx = "r";
+ link = pfx $1 ((den * 8) + drive);
+ if (tapelink[link] "" == "") {
+ out(link, "rmt/");
+ tapelink[link] = 1;
+ }
+ }
+#
+# Obsolete drive entries
+#
+$1 == "mt" {
+ if (($2 % 8) >= 4) {
+ link = "rmt" $2;
+ if (tapelink[link] "" == "") {
+ out(link, "rmt/", "nrmt" ($2 - 4));
+ tapelink[link] = 1;
+ }
+ }
+ else {
+ link = "rmt" $2;
+ if (tapelink[link] "" == "") {
+ out(link, "rmt/");
+ tapelink[link] = 1;
+ }
+ }
+ }
+
+#
+# Wierd Archive tape stuff
+#
+$1 == "ar" && NF == 5 && $5 !~ /n$/ {
+ link = "rar" ($2/4);
+ if (tapelink[link] "" == "") {
+ out(link, "rmt/");
+ tapelink[link] = 1;
+ }
+ }
+$1 == "ar" && NF == 5 && $5 ~ /n$/ {
+ link = "nrar" (($2-16)/4);
+ if (tapelink[link] "" == "") {
+ out(link, "rmt/");
+ tapelink[link] = 1;
+ }
+ }
+#
+# Screen-buffers are easy
+#
+$1 == "bwtwo" || $1 == "cgthree" || $1 == "cgsix" || $1 == "cgfour" || $1 == "cgfourteen" || $1 == "cgeight" || $1 == "cgnine" || $1 == "cgtwelve" {
+ out("" $5, "fbs/");
+ }
+#
+# This catches the on-board ports, the 1st and second SCSI-board uarts,
+# as well as the newer fast-serial "se" ports.
+# Depends on the driver creating the right names.
+#
+($1 == "zs" || $1 == "se" || $1 == "su") && $4 !~ /,cu$/ && ttbeenhere != 1 {
+ ttbeenhere = 1;
+ system("x=`ls term`; for i in $x ; do rm -f tty$i; ln -s term/$i tty$i ; done");
+ }
+#
+# XXX Bus device support yet to go in, so the following are TBD:
+#
+# sbus vme16d16 vme24d16 vme32d16 vme32d32
+#
+#
+# XXX Other device support to be added as drivers are added:
+#
+# mcp oct mti
+#
diff --git a/usr/src/ucbcmd/ucblinks/ucblinks.c b/usr/src/ucbcmd/ucblinks/ucblinks.c
new file mode 100644
index 0000000000..3172abc58d
--- /dev/null
+++ b/usr/src/ucbcmd/ucblinks/ucblinks.c
@@ -0,0 +1,1456 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 1998, 2000, 2002 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+/*
+ * ucblinks - create 4.x /dev compatibility names
+ *
+ * The basic algorithm is:
+ *
+ * find block and character special files in /devices with major
+ * numbers of devices that need compatibility names
+ *
+ * determine compatibility names from minor number, driver name, and
+ * /devices name
+ *
+ * create symlinks for the compatibility names to 5.x /dev
+ * entries if possible or /devices entries if necessary
+ *
+ * The name space that ucblinks creates has a number of problems.
+ * Unfortunately people have, to an unknown extent, come to depend
+ * on the broken name space. Fixing ucblinks to be more compatible
+ * with 4.x would make it less compatible with previous releases of
+ * 5.x. The places were it is broken are noted throughout the code
+ * and summarized here:
+ *
+ * 1157501 ucblinks creates completely broken 4.x links for IPI
+ * 1157616 ucblinks does 0 <-> 3 swap for disks when it shouldn't
+ * 1157617 ucblinks creates /dev/rxt* names instead of /dev/rmt*
+ * 1157970 ucblinks creates incompatible and overlapping links for tapes
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <ftw.h>
+#include <sys/types.h>
+#include <sys/mkdev.h>
+#include <sys/param.h>
+#include <locale.h>
+#include <libdevinfo.h>
+
+static char *progname;
+static char *rootdir = NULL; /* an alternate root to / */
+static int debug = 0; /* only print what is right and wrong */
+static int depth; /* num descriptors to use for nftw() */
+
+/*
+ * Each block or character device entry in /devices is
+ * represented by one of these structures.
+ */
+struct devices_ent {
+ char *devicename; /* /devices name */
+ char *min_comp; /* minor component of name */
+ int minor; /* minor number */
+ int israw; /* character device? */
+ int iscd; /* cdrom? */
+ int csum; /* checksum of name */
+ struct symlink *linksto; /* symlinks to this name */
+ struct drvinfo *drp; /* driver for this name */
+ struct devices_ent *next; /* for hash table */
+};
+
+/*
+ * There are a set of devices for which we'll create
+ * compatibility names. Each driver for the devices
+ * is represented by a drvinfo structure. The rule_func
+ * field points to a rule function for that driver.
+ */
+typedef void (rule_func_t)(struct devices_ent *);
+
+struct drvinfo {
+ char *name; /* driver name from name_to_major */
+ int major; /* major number */
+ int index; /* index, for sorting */
+ rule_func_t *rule_func; /* rule for this driver */
+};
+
+/*
+ * The rules for the drivers.
+ */
+static rule_func_t rule_ar; /* Archive tapes */
+static rule_func_t rule_atapicd; /* PCI cdrom drive */
+static rule_func_t rule_fbs; /* frame buffers */
+static rule_func_t rule_fd; /* floppy disk */
+static rule_func_t rule_id; /* IPI disks */
+static rule_func_t rule_mt; /* mt tapes */
+static rule_func_t rule_sd; /* scsi disks */
+static rule_func_t rule_stxt; /* scsi and xt tapes */
+static rule_func_t rule_xdxy; /* xd and xy disks */
+static rule_func_t rule_zs; /* zs serial */
+
+#define NOMAJ (-1) /* no entry in /etc/name_to_major */
+
+/*
+ * Below are the devices for which we create compatibility
+ * links. Some are obsolete as they have no /etc/name_to_major
+ * entry, but they're here to be compatible with the awk-based
+ * version of ucblinks. This list should be in alphabetical
+ * order with the index field set for the position in the array
+ * (we could compute it at runtime, but we know it so we set
+ * it here). See dcomp() for more about sort order.
+ */
+static struct drvinfo drvs[] = {
+ { "ar", NOMAJ, 0, rule_ar }, /* obsolete */
+ { "atapicd", NOMAJ, 1, rule_atapicd },
+ { "bwtwo", NOMAJ, 1, rule_fbs },
+ { "cgeight", NOMAJ, 2, rule_fbs },
+ { "cgfour", NOMAJ, 3, rule_fbs }, /* obsolete */
+ { "cgfourteen", NOMAJ, 4, rule_fbs }, /* obsolete */
+ { "cgnine", NOMAJ, 5, rule_fbs },
+ { "cgsix", NOMAJ, 6, rule_fbs },
+ { "cgthree", NOMAJ, 7, rule_fbs },
+ { "cgtwelve", NOMAJ, 8, rule_fbs }, /* obsolete */
+ { "fd", NOMAJ, 9, rule_fd },
+ { "id", NOMAJ, 10, rule_id },
+ { "mt", NOMAJ, 11, rule_mt }, /* obsolete */
+ { "sd", NOMAJ, 12, rule_sd },
+ { "st", NOMAJ, 13, rule_stxt },
+ { "xd", NOMAJ, 14, rule_xdxy },
+ { "xt", NOMAJ, 15, rule_stxt },
+ { "xy", NOMAJ, 16, rule_xdxy },
+ { "zs", NOMAJ, 17, rule_zs },
+ { "se", NOMAJ, 18, rule_zs }, /* Fast serial */
+ { "su", NOMAJ, 19, rule_zs }, /* PC/16550 serial */
+ { NULL },
+};
+
+/*
+ * Each symlink in /dev is represented by a symlink structure.
+ * We record all of them, not just those that point to interesting
+ * /devices entries, because when we have determined what a
+ * compatibility link should point to we want to know if it
+ * already points to the correct target and it is much cheaper to
+ * look it up in our list than to make a system call.
+ */
+struct symlink {
+ char *linkname; /* name of link */
+ char *target; /* what the link points to */
+ int csum; /* checksum of linkname */
+ int already; /* link already made */
+ struct symlink *hashnext; /* next on hash list */
+ struct symlink *deventnext; /* next on /devices ent list */
+};
+
+/*
+ * The /devices entries and the /dev symlinks are kept in
+ * (separate) hash tables. HASHSIZE was pulled out of the
+ * air although it seems to work ok and we get a good
+ * distribution. Some theory says this should be prime,
+ * but I don't understand why and that would make "% HASHSIZE"
+ * a call to mod routine rather than a simple bit-wise and.
+ */
+#define HASHSIZE 256
+static struct devices_ent *de_hashtab[HASHSIZE];
+static struct devices_ent **devices_list;
+static int num_devices_ents;
+
+static struct symlink *link_hashtab[HASHSIZE];
+
+/*
+ * Buffers used by the rule functions to construct link names.
+ */
+static char namebuf[MAXPATHLEN + 1];
+static char namebuf2[MAXPATHLEN + 1];
+
+/*
+ * Handle used for the link database
+ */
+static di_devlink_handle_t link_handle;
+
+static void exec_script(char **argv);
+static void get_major_nums(void);
+static void set_depth(void);
+static void get_devices(void);
+static void get_dev_links(void);
+static void call_device_rules(void);
+
+/*
+ * The command-line arguments to ucblinks are:
+ *
+ * -r specify a root relative to which ./devices and ./dev
+ * are used to create links.
+ *
+ * -e the awk-based ucblinks had a default rule-base and
+ * allowed alternate rule-bases with -e. If the user
+ * specifies a rule-base we run the awk-based ucblinks
+ * and pass all the args to it.
+ *
+ * -d undocumented debug option (like the awk-based version);
+ * print what would be created, fixed, or is already correct.
+ */
+int
+main(int argc, char **argv)
+{
+ int c;
+ int err = 0;
+
+ (void) setlocale(LC_ALL, "");
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ progname = argv[0]; /* save program name for error messages */
+
+ while ((c = getopt(argc, argv, "r:e:d")) != EOF) {
+ switch (c) {
+ case 'r':
+ rootdir = optarg;
+ break;
+ case 'e':
+ exec_script(argv);
+ /* exec_script doesn't return */
+ break;
+ case 'd':
+ debug = 1;
+ break;
+ case '?':
+ default:
+ err = 1;
+ break;
+ }
+ }
+
+ if (err || (optind != argc)) {
+ (void) fprintf(stderr, gettext("usage: %s [ -r rootdir ] "
+ "[ -e rulebase ]\n"), progname);
+ exit(1);
+ }
+
+ get_major_nums();
+
+ set_depth();
+
+ get_devices();
+
+ get_dev_links();
+
+ call_device_rules();
+
+ return (0);
+}
+
+/*
+ * A utility function so we don't have to check the return
+ * value of malloc for NULL all over the place.
+ */
+static void *
+xmalloc(size_t size)
+{
+ void *p;
+
+ p = malloc(size);
+ if (p != NULL)
+ return (p);
+ else {
+ (void) fprintf(stderr, gettext("%s: malloc failed, "
+ "out of memory\n"), progname);
+ exit(1);
+#ifdef lint
+ return (NULL);
+#endif
+ }
+}
+
+/*
+ * A utility function so we don't have to check the return
+ * value of strdup (which gets space from malloc) for NULL
+ * all over the place.
+ */
+static char *
+xstrdup(const char *s1)
+{
+ char *s2;
+
+ s2 = strdup(s1);
+ if (s2 != NULL)
+ return (s2);
+ else {
+ (void) fprintf(stderr, gettext("%s: malloc failed, "
+ "out of memory\n"), progname);
+ exit(1);
+#ifdef lint
+ return (NULL);
+#endif
+ }
+}
+
+/*
+ * A utility function that prepends the program name to
+ * perror output.
+ */
+static void
+xperror(const char *errstr)
+{
+ int len1, len2;
+ char *msg;
+
+ len1 = strlen(progname);
+ len2 = strlen(errstr);
+
+ msg = xmalloc(len1 + 2 + len2 + 1);
+ (void) sprintf(msg, "%s: %s", progname, errstr);
+ perror(msg);
+ free(msg);
+}
+
+/*
+ * The awk-based ucblinks allowed an alternate rule-base with
+ * the -e option. Obviously we don't do awk, so pass off all
+ * our command-line arguments to the awk-based version which
+ * was moved from /usr/ucb to /usr/ucblib.
+ */
+#define SCRIPT "/usr/ucblib/ucblinks.sh"
+
+static void
+exec_script(char **argv)
+{
+ argv[0] = SCRIPT;
+ if (execv(SCRIPT, argv) == -1)
+ xperror(gettext("cannot execute " SCRIPT));
+ exit(1);
+}
+
+/*
+ * Construct a name with the rootdir, if specified with -r,
+ * prepended. Don't free this because when rootdir isn't
+ * set we return what was passed in (this is called at most
+ * four times so it's no big deal to not free it).
+ */
+static char *
+root_name(char *name)
+{
+ int len1, len2;
+ char *buf;
+
+ if (rootdir == NULL)
+ return (name);
+ else {
+ len1 = strlen(rootdir);
+ len2 = strlen(name);
+ buf = xmalloc(len1 + len2 + 1);
+
+ (void) strcpy(buf, rootdir);
+ (void) strcpy(buf + len1, name);
+ return (buf);
+ }
+}
+
+/*
+ * Read /etc/name_to_major to find the major numbers associated
+ * with the names in the drvinfo array. We silently ignore
+ * what we don't understand.
+ */
+static void
+get_major_nums(void)
+{
+ FILE *fp;
+ char line[80];
+ char *name, *maj, *end;
+ int majnum;
+ struct drvinfo *drp;
+
+ fp = fopen("/etc/name_to_major", "r");
+ if (fp == NULL) {
+ (void) fprintf(stderr, gettext("%s: cannot open "
+ "/etc/name_to_major\n"), progname);
+ exit(1);
+ }
+
+ while (fgets(line, sizeof (line), fp) != NULL) {
+ name = strtok(line, " \t");
+ if (name == NULL)
+ continue;
+
+ maj = strtok(NULL, "\n");
+ if (maj == NULL)
+ continue;
+
+ majnum = strtol(maj, &end, 10);
+ if (end == maj)
+ continue;
+
+ /*
+ * Compare against our list and set the major
+ * number it it's a name we care about.
+ */
+ for (drp = drvs; drp->name != NULL; drp++) {
+ if (strcmp(name, drp->name) == 0) {
+ drp->major = majnum;
+ break;
+ }
+ }
+ }
+
+ (void) fclose(fp);
+}
+
+/*
+ * Pick some reasonable number of file descriptors to let nftw()
+ * have open at a time. The number shouldn't be more than the
+ * currently available file descriptors but should be at least equal
+ * to the depth of the trees we're traversing for efficiency. Of
+ * course we don't know how deep the trees are before hand, so
+ * just use half the allowable descriptors which usually comes
+ * out to 32 which is usually more than enough. Using a depth
+ * smaller than the tree depth doesn't prevent traversal of the tree,
+ * it just makes it slower. sysconf() can't fail, but if it does
+ * use a depth of 1.
+ */
+static void
+set_depth(void)
+{
+ long num;
+
+ num = sysconf(_SC_OPEN_MAX);
+ if (num == -1)
+ depth = 1;
+ else
+ depth = num / 2;
+}
+
+/*
+ * Given a major number look it up in our list to see if it
+ * is associated with a device that needs a compatibility
+ * link. We cache the last lookup to avoid going through
+ * the list each time.
+ */
+static struct drvinfo *
+interesting_major(int major)
+{
+ struct drvinfo *drp;
+ static int last_major = -1;
+ static struct drvinfo *last_result = NULL;
+
+ if (major == last_major)
+ return (last_result);
+ last_major = major;
+
+ for (drp = drvs; drp->name != NULL; drp++) {
+ if (major == drp->major) {
+ last_result = drp;
+ return (drp);
+ }
+ }
+
+ last_result = NULL;
+ return (NULL);
+}
+
+/*
+ * Find the minor component of the device name which is what
+ * comes between the ':' and ',' in the last component of
+ * the pathname; make a copy and return a pointer to it.
+ */
+static char *
+find_min_comp(char *name)
+{
+ char *cp1, *cp2;
+ int len;
+ char *buf;
+
+ cp1 = strrchr(name, '/');
+ if (cp1 == NULL)
+ cp1 = name;
+ else
+ cp1++; /* skip '/' */
+ cp1 = strchr(cp1, ':');
+ if (cp1 == NULL)
+ return ("");
+
+ cp1++; /* skip ':' */
+ cp2 = cp1;
+ while (*cp2 != ',' && *cp2 != '\0')
+ cp2++;
+ len = cp2 - cp1;
+ if (len == 0)
+ return ("");
+
+ buf = xmalloc(len + 1);
+ (void) strncpy(buf, cp1, len);
+ buf[len] = '\0';
+ return (buf);
+}
+
+/*
+ * To get an index into the hash table we compute a checksum
+ * of the string and mod HASHSIZE. The checksum came from
+ * awk, although we do a shift and subtract to implement
+ * multiplication by 31. We return the index as well as
+ * the whole checksum. The checksum is useful for efficient
+ * symbol lookup because the hash table will contain long strings
+ * that can be the same for the first 70 characters or more, so
+ * we compare checksums first before using strcmp().
+ */
+static int
+hash_sym(char *name, int *csp)
+{
+ char c;
+ unsigned int csum = 0;
+
+ while ((c = *name++) != '\0')
+ csum = ((csum << 5) - csum) + c;
+
+ *csp = csum;
+ return (csum % HASHSIZE);
+}
+
+/*
+ * Insert a /devices entry symbol into the devices entry
+ * hash table.
+ */
+static void
+insert_devices_sym(struct devices_ent *dep)
+{
+ int hash;
+ struct devices_ent **pp;
+
+ hash = hash_sym(dep->devicename, &dep->csum);
+ pp = &de_hashtab[hash];
+ dep->next = *pp;
+ *pp = dep;
+}
+
+/*
+ * Lookup a symbol in the devices entry hash table. Use
+ * the checksum to reduce the number of strcmp() calls.
+ */
+static struct devices_ent *
+lookup_devices_sym(char *devicename)
+{
+ int hash;
+ struct devices_ent *dep;
+ int csum;
+
+ hash = hash_sym(devicename, &csum);
+ dep = de_hashtab[hash];
+ while (dep != NULL) {
+ if (csum == dep->csum) {
+ if (strcmp(devicename, dep->devicename) == 0)
+ return (dep);
+ }
+ dep = dep->next;
+ }
+
+ return (NULL);
+}
+
+/*
+ * This routine is called from nftw() for each /devices entry.
+ * If it isn't a device special file or doesn't have the major
+ * number of something we care about, don't do anything.
+ * Otherwise, allocate a structure for it and put it in the
+ * hash table.
+ */
+/* ARGSUSED2 */
+static int
+devices_entry(const char *name, const struct stat *sp,
+ int flags, struct FTW *ftwp)
+{
+ int type;
+ struct drvinfo *drp;
+ struct devices_ent *dep;
+
+ if (flags == FTW_NS) { /* couldn't stat the file */
+ (void) fprintf(stderr, gettext("%s: cannot stat %s\n"),
+ progname, name);
+ return (0);
+ }
+ if (flags == FTW_DNR) { /* couldn't read a directory */
+ (void) fprintf(stderr, gettext("%s: cannot read "
+ "directory %s\n"), progname, name);
+ return (0);
+ }
+
+ type = sp->st_mode & S_IFMT;
+ if (!(type == S_IFCHR || type == S_IFBLK))
+ return (0);
+
+ drp = interesting_major(major(sp->st_rdev));
+ if (drp == NULL)
+ return (0);
+
+ name += 2; /* skip "./" */
+ dep = xmalloc(sizeof (struct devices_ent));
+ dep->devicename = xstrdup(name);
+ dep->min_comp = find_min_comp(dep->devicename);
+ dep->minor = minor(sp->st_rdev);
+ dep->israw = (type == S_IFCHR);
+ dep->iscd = 0;
+ dep->linksto = NULL;
+ dep->drp = drp;
+
+ insert_devices_sym(dep);
+ num_devices_ents++;
+
+ return (0);
+}
+
+/*
+ * dcomp is the sort function called from qsort(). When comparing
+ * two device entries we sort by alphabetical order of the device's
+ * driver name, then minor number, then block vs. character, then
+ * the name of the device entry itself.
+ */
+static int
+dcomp(const void *p1, const void *p2)
+{
+ struct devices_ent *dep1 = *((struct devices_ent **)p1);
+ struct devices_ent *dep2 = *((struct devices_ent **)p2);
+
+ if (dep1->drp->index == dep2->drp->index) {
+ if (dep1->minor == dep2->minor) {
+ if (dep1->israw == dep2->israw) {
+ return (strcoll(dep1->devicename,
+ dep2->devicename));
+ } else {
+ return (dep1->israw - dep2->israw);
+ }
+ } else {
+ return (dep1->minor - dep2->minor);
+ }
+ } else {
+ return (dep1->drp->index - dep2->drp->index);
+ }
+}
+
+/*
+ * Go to the /devices directory and recursively find all
+ * the device special files (with the handy library function
+ * nftw). nftw() will call devices_entry() which will put
+ * the entry in the hash table. After we find all the
+ * entries allocate a table and put pointers in it so
+ * we can sort the entries.
+ */
+static void
+get_devices(void)
+{
+ char *dir;
+ int i;
+ struct devices_ent *dep, **pht, **pdep;
+
+ dir = root_name("/devices");
+ if (chdir(dir) == -1) {
+ xperror(dir);
+ exit(1);
+ }
+
+ /*
+ * Errors related to access permissions are handled
+ * by devices_entry() and devices_entry doesn't return
+ * non-zero so the only thing left is some other type
+ * of error.
+ */
+ if (nftw(".", devices_entry, depth, FTW_PHYS) == -1)
+ xperror("nftw()");
+
+ devices_list = xmalloc(sizeof (struct devices_ent *) *
+ num_devices_ents);
+
+ pdep = devices_list;
+ pht = de_hashtab;
+ for (i = 0; i < HASHSIZE; i++) {
+ dep = *pht;
+ while (dep != NULL) {
+ *pdep++ = dep;
+ dep = dep->next;
+ }
+ pht++;
+ }
+
+ /*
+ * After all the /devices entries are put in the hash
+ * table we sort the entries. We do this for two
+ * reasons: the rule functions may count on the order of
+ * devices it is called with (like the cdrom stuff in
+ * rule_sd) and if the rules create overlapping names the
+ * links will be made in an order based on sorted entries
+ * rather than be dependent on the order the entries
+ * happen to be in in a directory.
+ */
+ qsort((void *) devices_list, num_devices_ents,
+ sizeof (struct devices_ent *), dcomp);
+}
+
+/*
+ * Like insert_devices_sym, but for link names and symlink
+ * structures.
+ */
+static void
+insert_link_sym(struct symlink *slp)
+{
+ int hash;
+ struct symlink **pp;
+
+ hash = hash_sym(slp->linkname, &slp->csum);
+ pp = &link_hashtab[hash];
+ slp->hashnext = *pp;
+ *pp = slp;
+}
+
+/*
+ * Like lookup_devices_sym, but for link names and symlink
+ * structures.
+ */
+static struct symlink *
+lookup_link_sym(char *linkname)
+{
+ int hash;
+ struct symlink *slp;
+ int csum;
+
+ hash = hash_sym(linkname, &csum);
+ slp = link_hashtab[hash];
+ while (slp != NULL) {
+ if (csum == slp->csum) {
+ if (strcmp(linkname, slp->linkname) == 0)
+ return (slp);
+ }
+ slp = slp->hashnext;
+ }
+
+ return (NULL);
+}
+
+/*
+ * Check this symlink to see if it points to an interesting
+ * /devices entry and hang it off the entry if it does.
+ */
+static void
+check_link(struct symlink *slp)
+{
+ int dirs;
+ char *cp;
+ int len;
+ char *devices = "../devices/";
+ char *buf;
+ int i, off;
+ struct devices_ent *dep;
+
+ if (*slp->target != '.')
+ return;
+
+ /*
+ * Figure out how many directories deep the entry is
+ * so we can see if its link has the right number of
+ * ".."s to point to the /devices directory.
+ */
+ dirs = 0;
+ cp = strchr(slp->linkname, '/');
+ while (cp != NULL) {
+ dirs++;
+ cp = strchr(cp + 1, '/');
+ }
+ len = strlen(devices);
+ buf = xmalloc(dirs * 3 + len + 1);
+ for (i = 0, off = 0; i < dirs; i++, off += 3)
+ (void) strcpy(buf + off, "../");
+ (void) strcpy(buf + off, devices);
+ off += len;
+
+ /*
+ * The correct prefix of the path has been built up
+ * in "buf", compare it to the link and return
+ * if it doesn't match.
+ */
+ if (strncmp(slp->target, buf, strlen(buf)) != 0) {
+ free(buf);
+ return;
+ }
+ free(buf);
+
+ /*
+ * Look up the /devices path (minus the prefix) and
+ * return if not found.
+ */
+ dep = lookup_devices_sym(slp->target + off);
+ if (dep == NULL)
+ return;
+
+ /* hang it off the /devices entry */
+ slp->deventnext = dep->linksto;
+ dep->linksto = slp;
+
+}
+
+/*
+ * This routine is called from nftw() for each /dev entry.
+ * We record all of the symlinks, not just those that point to
+ * interesting /devices entries, because when we have determined
+ * what a compatibility link should point to we want to know
+ * if it already points to the correct target and it is much
+ * cheaper to look it up in out list than to make a system call.
+ */
+/* ARGSUSED2 */
+static int
+dev_entry(const char *name, const struct stat *sp,
+ int flags, struct FTW *ftwp)
+{
+ int type;
+ char target[MAXPATHLEN + 1];
+ int targetlen;
+ struct symlink *slp;
+
+ if (flags == FTW_NS) { /* couldn't stat the file */
+ (void) fprintf(stderr, gettext("%s: cannot stat %s\n"),
+ progname, name);
+ return (0);
+ }
+ if (flags == FTW_DNR) { /* couldn't read a directory */
+ (void) fprintf(stderr, gettext("%s: cannot read "
+ "directory %s\n"), progname, name);
+ return (0);
+ }
+
+ type = sp->st_mode & S_IFMT;
+ if (type != S_IFLNK)
+ return (0);
+
+ name += 2; /* skip "./" */
+ targetlen = readlink(name, target, sizeof (target));
+ if (targetlen == -1)
+ xperror(name);
+
+ target[targetlen] = '\0';
+
+ slp = xmalloc(sizeof (struct symlink));
+ slp->linkname = xstrdup(name);
+ slp->target = xstrdup(target);
+ slp->already = 0;
+ insert_link_sym(slp);
+ check_link(slp);
+
+ return (0);
+}
+
+/*
+ * Go to the /dev directory and recursively find all the
+ * symlinks. nftw() will call dev_entry() which will put
+ * the entry in the hash table.
+ */
+static void
+get_dev_links(void)
+{
+ char *devdir;
+
+ devdir = root_name("/dev");
+ if (chdir(devdir) == -1) {
+ xperror(devdir);
+ exit(1);
+ }
+
+ /*
+ * Errors related to access permissions are handled
+ * by dev_entry() and dev_entry doesn't return non-zero
+ * so the only thing left is some other type of error.
+ */
+ if (nftw(".", dev_entry, depth, FTW_PHYS) == -1)
+ xperror("nftw()");
+}
+
+/*
+ * Spin through our sorted list of /devices entries and call
+ * the rule function for each.
+ */
+static void
+call_device_rules(void)
+{
+ struct devices_ent **pdep;
+ struct devices_ent *dep;
+ int i;
+
+ link_handle = di_devlink_open(rootdir, 0);
+
+ pdep = devices_list;
+ for (i = 0; i < num_devices_ents; i++) {
+ dep = *pdep++;
+ dep->drp->rule_func(dep);
+ }
+
+ di_devlink_close(&link_handle, 0);
+}
+
+static void
+update_db(char *compat_link, char *target, int link_type)
+{
+ if (debug) {
+ (void) printf("adding %s link to database: %s -> %s\n",
+ link_type == DI_PRIMARY_LINK ? "primary" : "secondary",
+ compat_link, target);
+ } else {
+ (void) di_devlink_add_link(link_handle, compat_link, target,
+ link_type);
+ }
+}
+
+/*
+ * Create a symlink called compat_link that points to target.
+ * If it already exists correctly don't do anything. If it
+ * exists but is incorrect, delete the link and make it. If
+ * it doesn't exist just make it.
+ */
+static void
+make_link(
+ char *compat_link,
+ char *target,
+ struct symlink *compat_slp,
+ int link_type)
+{
+ if (compat_slp->target != NULL) {
+ if (strcmp(target, compat_slp->target) == 0) {
+ if (debug)
+ (void) printf("already %s -> %s\n",
+ compat_link, compat_slp->target);
+ update_db(compat_link, target, link_type);
+ return;
+ } else {
+ if (debug)
+ (void) printf("remove %s, link wrong (%s)\n",
+ compat_link, compat_slp->target);
+ else {
+ if (unlink(compat_link) == -1)
+ xperror(compat_link);
+ else
+ (void) di_devlink_rm_link(link_handle,
+ compat_link);
+ }
+ compat_slp->target = target;
+ }
+ } else
+ compat_slp->target = target;
+
+ if (debug)
+ (void) printf("link %s -> %s\n", compat_link, target);
+ else {
+ if (symlink(target, compat_link) == -1)
+ xperror(compat_link);
+ else
+ update_db(compat_link, target, link_type);
+ }
+}
+
+/*
+ * addlink is called from the rule functions when they want a
+ * compatibility link made. At this point we only know the
+ * link name, the /devices entry, and the prefix of a 5.x /dev
+ * name (that points to the /devices entry) that the rule would
+ * prefer the compatibility link point to. If a symlink already
+ * exists with the required prefix that points to the /devices
+ * entry, make the compatibility link point to that link.
+ * If a link with the required prefix doesn't exist, make the
+ * link point directly to the /devices entry. The idea is that
+ * someone looking at a compatibility link will be reminded of
+ * the "real" 5.x /dev name. For example, ls -l will show sd0a ->
+ * dsk/c0t3d0s0.
+ *
+ * If the symlink we're creating isn't already in the hash
+ * table we add it for possible future use by make_link.
+ * If multiple /devices entries exist with the same major
+ * and minor numbers this prevents problems with trying to
+ * make the link twice. Generally, though, there shouldn't
+ * be multiple /devices entries of the same type, major, and
+ * minor, except for tape devices. The tape rules pass 1 for
+ * the unique argument (all others pass 0) so we keep track
+ * and only create the first link for a particular compatibility
+ * name.
+ */
+static void
+addlink(char *compat_link, char *prefix, struct devices_ent *dep, int unique)
+{
+ int len, link_type = 0;
+ struct symlink *devent_slp;
+ struct symlink *compat_slp;
+ char *target = NULL;
+ char linkbuf[MAXPATHLEN + 1];
+
+ compat_slp = lookup_link_sym(compat_link);
+ if (compat_slp == NULL) {
+ compat_slp = xmalloc(sizeof (struct symlink));
+ compat_slp->linkname = xstrdup(compat_link);
+ compat_slp->target = NULL;
+ compat_slp->already = 0;
+ insert_link_sym(compat_slp);
+ }
+
+ if (unique) {
+ if (compat_slp->already)
+ return;
+ else
+ compat_slp->already = 1;
+ }
+
+ /*
+ * Look for a name with the correct prefix.
+ */
+ len = strlen(prefix);
+ devent_slp = dep->linksto;
+ while (devent_slp != NULL) {
+ if (strncmp(prefix, devent_slp->linkname, len) == 0) {
+ target = devent_slp->linkname;
+ link_type = DI_SECONDARY_LINK;
+ break;
+ }
+ devent_slp = devent_slp->deventnext;
+ }
+
+ /*
+ * If we didn't find one with the prefix, point directly
+ * to the /devices entry.
+ */
+ if (target == NULL) {
+ link_type = DI_PRIMARY_LINK;
+ (void) sprintf(linkbuf, "../devices/%s", dep->devicename);
+ target = xstrdup(linkbuf);
+ }
+ make_link(compat_link, target, compat_slp, link_type);
+}
+
+/*
+ * This is like addlink(), but it doesn't try to find a 5.x
+ * link to point to. It is used by the rule functions to add
+ * additional links to links already created with addlink().
+ */
+static void
+addlink_nolookup(char *compat_link, char *target, int unique)
+{
+ struct symlink *slp;
+ char *oldtarg;
+
+ slp = lookup_link_sym(compat_link);
+ if (slp == NULL) {
+ slp = xmalloc(sizeof (struct symlink));
+ slp->linkname = xstrdup(compat_link);
+ slp->target = NULL;
+ slp->already = 0;
+ insert_link_sym(slp);
+ }
+ oldtarg = slp->target;
+
+ if (unique) {
+ if (slp->already)
+ return;
+ else
+ slp->already = 1;
+ }
+
+ make_link(compat_link, target, slp, DI_SECONDARY_LINK);
+
+ /*
+ * If it didn't exist or pointed to the wrong
+ * thing we need to duplicate the target and
+ * note that the symlink now points to it.
+ */
+ if (slp->target != oldtarg)
+ slp->target = xstrdup(target);
+}
+
+/*
+ * The rest of this file is rule functions and support routines
+ * for the rules. Each rule is passed a pointer to a devices_ent
+ * struct which should be all it needs to determine what
+ * compatibility link is needed. The rule functions use
+ * addlink() and addlink_nolookup() to have the links
+ * made.
+ */
+
+/*
+ * Rule for Archive tapes. "ar" isn't in name_to_major but
+ * the awk-based version had a rule so it is here too. The
+ * rule works the same as the awk rule, but who knows if it
+ * is correct.
+ */
+static void
+rule_ar(struct devices_ent *dep)
+{
+ char *min_comp = dep->min_comp;
+
+ if (*min_comp != '\0') {
+ if (min_comp[strlen(min_comp) - 1] == 'n')
+ (void) sprintf(namebuf, "%s%d", "nrar",
+ (dep->minor - 16) / 4);
+ else
+ (void) sprintf(namebuf, "%s%d", "rar", dep->minor / 4);
+
+ addlink(namebuf, "rmt/", dep, 1);
+ }
+}
+
+/*
+ * Rule for frame buffers.
+ */
+static void
+rule_fbs(struct devices_ent *dep)
+{
+ addlink(dep->min_comp, "fbs/", dep, 0);
+}
+
+/*
+ * Rule for floppy drivers.
+ */
+static void
+rule_fd(struct devices_ent *dep)
+{
+ int c_slice;
+ int minor = dep->minor;
+ char *link_pfx;
+ char *targ_pfx;
+
+ c_slice = (strcmp(dep->min_comp, "c") == 0);
+
+ if (dep->israw) {
+ link_pfx = "r";
+ targ_pfx = "rdiskette";
+ } else {
+ link_pfx = "";
+ targ_pfx = "diskette";
+ }
+
+ (void) sprintf(namebuf, "%sfd%d%s", link_pfx, minor / 8,
+ dep->min_comp);
+ addlink(namebuf, targ_pfx, dep, 0);
+ if (c_slice) {
+ (void) sprintf(namebuf2, "%sfd%d", link_pfx, minor / 8);
+ addlink_nolookup(namebuf2, namebuf, 0);
+ }
+}
+
+/*
+ * Rule for IPI disks. This is hopelessly broken (see bug 1157501)
+ * but someone may have come to depend on the broken names.
+ */
+static void
+rule_id(struct devices_ent *dep)
+{
+ char *targ_pfx;
+ char *link_pfx;
+
+ if (dep->israw) {
+ link_pfx = "r";
+ targ_pfx = "rdsk/";
+ } else {
+ link_pfx = "";
+ targ_pfx = "dsk/";
+ }
+
+ (void) sprintf(namebuf, "%sid%x%s", link_pfx, dep->minor,
+ dep->min_comp);
+ addlink(namebuf, targ_pfx, dep, 0);
+}
+
+/*
+ * Rule for obsolete mt devices. It works like the awk rule,
+ * but unknown if correct.
+ */
+static void
+rule_mt(struct devices_ent *dep)
+{
+ int minor = dep->minor;
+
+ if ((minor % 8) >= 4) {
+ (void) sprintf(namebuf, "rmt%d", minor);
+ addlink(namebuf, "rmt/", dep, 1);
+ (void) sprintf(namebuf2, "nrmt%d", minor - 4);
+ addlink_nolookup(namebuf2, namebuf, 1);
+ } else {
+ (void) sprintf(namebuf, "rmt%d", minor);
+ addlink(namebuf, "rmt/", dep, 1);
+ }
+}
+
+
+static int
+find_cd_nodes(di_node_t node, di_minor_t minor, void *arg)
+{
+ char *path;
+ char devpath[MAXPATHLEN];
+ struct devices_ent *dep;
+
+ path = di_devfs_path(node);
+
+ if (*path == '/') {
+ (void) strcpy(devpath, path+1);
+ (void) strcat(devpath, ":");
+ (void) strcat(devpath, di_minor_name(minor));
+
+ dep = lookup_devices_sym(devpath);
+ if (dep != NULL) {
+ dep->iscd = 1;
+ }
+ }
+
+ di_devfs_path_free(path);
+
+ return (DI_WALK_CONTINUE);
+}
+
+
+/*
+ * The rule for scsi disks uses this to determine if the /devices
+ * entry corresponds to a cdrom drive. Use libdevinfo to walk
+ * the device tree, calling find_cd_nodes() for each minor
+ * node of type DDI_NT_CD.
+ */
+static void
+find_cds(void)
+{
+ di_node_t root_node;
+
+ root_node = di_init("/", DINFOSUBTREE|DINFOMINOR);
+ if (root_node == DI_NODE_NIL) {
+ return;
+ }
+ di_walk_minor(root_node, DDI_NT_CD, 0, NULL, find_cd_nodes);
+ di_fini(root_node);
+}
+
+
+
+/*
+ * Rule for scsi disks. If the entry is for a cdrom drive
+ * we create srN and rsrN where N is logically numbered
+ * starting at 0 in order of minor number. For regular
+ * disks we do the 0 <-> 3 swap, i.e., sd0a will point
+ * to c0t3d0s0 and sd3a will point to c0t0d0s0. This should
+ * only be done on sun4m machines to be compatible
+ * with 4.x (see bug 1157616) but we're probably stuck with it
+ * being done on all machines because people may be used
+ * to using the swapped names on other machines.
+ */
+static void
+rule_sd(struct devices_ent *dep)
+{
+ static int first = 1;
+ static int cdnum = -1;
+ static int last_minor = -1;
+ char *min_comp = dep->min_comp;
+ int minor = dep->minor;
+ char *targ_pfx;
+ char *link_pfx;
+
+ if (first) {
+ find_cds();
+ first = 0;
+ }
+
+ if (dep->iscd) {
+ if (strcmp(min_comp, "c") == 0) {
+ if (minor != last_minor) {
+ cdnum++;
+ last_minor = minor;
+ }
+ if (dep->israw) {
+ (void) sprintf(namebuf, "rsr%d", cdnum);
+ addlink(namebuf, "rdsk/", dep, 0);
+ } else {
+ (void) sprintf(namebuf, "sr%d", cdnum);
+ addlink(namebuf, "dsk/", dep, 0);
+ }
+ }
+ return;
+ }
+
+ if (dep->israw) {
+ link_pfx = "r";
+ targ_pfx = "rdsk/";
+ } else {
+ link_pfx = "";
+ targ_pfx = "dsk/";
+ }
+
+ if (minor < 8)
+ (void) sprintf(namebuf, "%ssd%d%s", link_pfx, 3, min_comp);
+ else if (minor >= 24 && minor < 32)
+ (void) sprintf(namebuf, "%ssd%d%s", link_pfx, 0, min_comp);
+ else
+ (void) sprintf(namebuf, "%ssd%d%s", link_pfx, minor / 8,
+ min_comp);
+
+ addlink(namebuf, targ_pfx, dep, 0);
+}
+
+/*
+ * Rule for PCI cdrom drives.
+ */
+static void
+rule_atapicd(struct devices_ent *dep)
+{
+ static int last_minor = -1;
+ static int cdnum = -1;
+ char *min_comp = dep->min_comp;
+ int minor = dep->minor;
+
+ if (strcmp(min_comp, "c") == 0) {
+ if (minor != last_minor) {
+ cdnum++;
+ last_minor = minor;
+ }
+ if (dep->israw) {
+ (void) sprintf(namebuf, "rsr%d", cdnum);
+ addlink(namebuf, "rdsk/", dep, 0);
+ } else {
+ (void) sprintf(namebuf, "sr%d", cdnum);
+ addlink(namebuf, "dsk/", dep, 0);
+ }
+ }
+}
+
+/*
+ * Rule for scsi and xt tapes. The tape name space has several
+ * problems (see bug 1157970) and the xt names should really appear
+ * as an "mt" name (see bug 1157617) but, again, we probably shouldn't
+ * change this now as it will break compatibility with earlier
+ * 5.x releases.
+ */
+
+#include <sys/mtio.h>
+/*
+ * MTUNIT() and MT_DENSITY() use getminor(), but we already have
+ * the minor number and including sysmacros.h to get getminor()
+ * conflicts with mkdev.h. Barf.
+ */
+#define getminor(d) (d)
+
+static void
+rule_stxt(struct devices_ent *dep)
+{
+ char *min_comp = dep->min_comp;
+ int minor = dep->minor;
+ int drive, den;
+ char *link_pfx;
+
+ if (*min_comp != 'b' && *min_comp != 'n') {
+ if ((minor & MT_BSD) == 0)
+ return; /* not BSD-style */
+
+ drive = MTUNIT(minor);
+ den = MT_DENSITY(minor);
+
+ if (min_comp[strlen(min_comp) - 1] == 'n')
+ link_pfx = "nr";
+ else
+ link_pfx = "r";
+ (void) sprintf(namebuf, "%s%s%d", link_pfx, dep->drp->name,
+ (den * 8) + drive);
+ addlink(namebuf, "rmt/", dep, 1);
+ }
+}
+
+/*
+ * Rule for xd and xy disks. This is broken because it does
+ * the 0 <-> 3 swap that should only be done for scsi disks
+ * on sun4m (see bug 1157616). Again, we probably
+ * can't change this now.
+ */
+static void
+rule_xdxy(struct devices_ent *dep)
+{
+ char *min_comp = dep->min_comp;
+ char *majname = dep->drp->name;
+ int minor = dep->minor;
+ char *targ_pfx;
+ char *link_pfx;
+
+ if (dep->israw) {
+ link_pfx = "r";
+ targ_pfx = "rdsk/";
+ } else {
+ link_pfx = "";
+ targ_pfx = "dsk/";
+ }
+
+ if (minor < 8)
+ (void) sprintf(namebuf, "%s%s%d%s", link_pfx, majname, 3,
+ min_comp);
+ else if (minor >= 24 && minor < 32)
+ (void) sprintf(namebuf, "%s%s%d%s", link_pfx, majname, 0,
+ min_comp);
+ else
+ (void) sprintf(namebuf, "%s%s%d%s", link_pfx, majname,
+ minor / 8, min_comp);
+
+ addlink(namebuf, targ_pfx, dep, 0);
+}
+
+/*
+ * Rule for zs (serial) devices. This rule is different from
+ * the rest because it doesn't create a link based on the
+ * /devices entry. It just uses the /devices entry to trigger
+ * the rule to create ttyN -> dev/term/N for all dev/term
+ * entries.
+ */
+#include <dirent.h>
+
+static void
+rule_zs(struct devices_ent *dep)
+{
+ static int beenhere = 0;
+ int len;
+ DIR *dirp;
+ struct dirent *direntp;
+ char *termdir;
+ char *entry;
+ char *devicename = dep->devicename;
+
+ len = strlen(devicename);
+ if (strncmp(&devicename[len - 3], ",cu", 3) == 0)
+ return;
+
+ if (beenhere)
+ return;
+ else
+ beenhere = 1;
+
+ termdir = root_name("/dev/term");
+
+ dirp = opendir(termdir);
+ if (dirp == NULL) {
+ xperror(termdir);
+ return;
+ }
+ while ((direntp = readdir(dirp)) != NULL) {
+ entry = direntp->d_name;
+ if (entry[0] == '.')
+ continue;
+ (void) sprintf(namebuf, "tty%s", direntp->d_name);
+ (void) sprintf(namebuf2, "term/%s", direntp->d_name);
+ addlink_nolookup(namebuf, namebuf2, 0);
+ }
+
+ (void) closedir(dirp);
+}
diff --git a/usr/src/ucbcmd/ucblinks/ucblinks.sh b/usr/src/ucbcmd/ucblinks/ucblinks.sh
new file mode 100644
index 0000000000..974b542d82
--- /dev/null
+++ b/usr/src/ucbcmd/ucblinks/ucblinks.sh
@@ -0,0 +1,234 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright (c) 1991 by Sun Microsystems, Inc.
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+
+PATH=/sbin:/usr/sbin:/usr/bin:/etc
+export PATH
+
+RULEBASE=/usr/ucblib/ucblinks.awk
+
+# Name of device-type list produced by "devlinks"
+DEVTYPES=/etc/.obp_devices
+
+USAGE="Usage: `basename $0` [-r rootdir] [-e rulebase] [-d]"
+DOIT_CMD="sh -s"
+
+while getopts 'de:r:' flag
+do
+ case $flag in
+ d) DOIT_CMD="cat -"
+ ;;
+ e)
+ RULEBASE=$OPTARG;
+ case "$RULEBASE" in
+ /*) ;;
+ *) RULEBASE="`pwd`/$RULEBASE";;
+ esac
+ ;;
+ r) ROOTDIR=$OPTARG;
+ ;;
+ \?) echo "$USAGE" >&2
+ exit 2;
+ ;;
+ esac
+done
+
+shift `expr $OPTIND - 1`
+
+#
+# The rest of this script looks a mess. But in fact underneath all the
+# 'sed's and 'awk's it is quite simple.
+#
+# First it creates a list of all the device nodes in the /devices directory
+# (by cd'ing to /dev, then doing a 'find' of all special files in ../devices
+# doing an 'ls -l' of these files, and sedding the output to produce a list
+# of the form 'major minor type name').
+#
+# As an added wrinkle it changes 'major' from a number to a driver-name using
+# sed rules produced from the "/etc/name_to_major file.
+#
+# Then it runs the awk rules in the rule-base on this list to produce a list
+# of compatability-links that must be created. However, this does not produce
+# the links themselves because of the next stage:
+#
+# Finally this list of compatability-links is inspected and where possible links
+# to the SunOS5 names are created instead of links directly to the /devices
+# directory
+# (by 'find'ing all the symbolic links under /dev, ancomparing the
+# subdirectory they occur in, and the file to which they point, to
+# the comaptability-link information built above. If a match is found
+# a command to make a link to the 5.0 link, rather than to the /devices
+# entry, is created. If not, a direct link is created)
+# And then the list of link command is executed by a shell, or printed on stdout
+# (in debugging mode)
+#
+# See -- not so complicated! However the syntax of all these rules makes
+# the code below nearly incomprehensible. Fear not; the only part you need
+# to change for extra devices is located in the 'RULEBASE' file.
+
+cd $ROOTDIR/dev
+
+GENSED=/tmp/mkcompat.sed$$
+GENAWK=/tmp/mkcompat.awk$$
+GENRULE=/tmp/mkcompat.rule$$
+
+rm -f $GENSED $GENAWK $GENRULE
+
+trap "rm -f $GENSED $GENAWK $GENRULE" 0
+
+#
+# First generate full rulebase. This is done to keep common functions
+# out of the rulebase
+
+
+cat - >$GENRULE <<\!EOD
+function out(dev, dir, extraname) {
+ c = split(dir, junk, "/") - 1;
+
+ if (junk[1] == ".")
+ c--;
+
+ fulldevfs = "";
+
+ while ( c > 0) {
+ fulldevfs = "../" fulldevfs;
+ c--;
+ }
+ fulldevfs = fulldevfs $4;
+
+ printf "devname[\"" fulldevfs "\"] = \"" dev "\";";
+
+ if (length(dir) > 0)
+ printf " devdir[\"" fulldevfs "\"] = \"" dir "\";";
+
+ if (length(extraname) > 0)
+ printf " devextra[\"" fulldevfs "\"] = \"" extraname "\";";
+ printf "\n";
+ }
+
+!EOD
+
+#
+# Now see if we need to do CD drive special handling. The SCSI CD and disk
+# drivers have been merged in SunOS5, so we cannot do the normal differentiation
+# on major number with these devices. However the "disks" program does write
+# a list of all OBP cd device names in a pecial file; by massaging this file
+# we are able to construct rules which correctly differentiate between sd and sr
+# devices.
+
+if [ -s $DEVTYPES ]
+then
+ echo "BEGIN {" >>$GENRULE
+ sed -ne '/^ddi_block:cdrom[: ]/s-^[^ ]*[ ]\{1,\}\(.*\)$- cddev["../devices/\1"] = 1;-p' <$DEVTYPES >>$GENRULE
+ echo " }" >>$GENRULE
+fi
+
+cat $RULEBASE >>$GENRULE
+
+
+#
+#----------------------------------------------------------------------
+#
+# Construct sedscr ... a script to massage the output of an 'ls -l'
+# of all the special files in the '../devices' directory.
+#
+# First 3 lines of scr change line to format "maj min [b|c] name
+#
+cat <<\!EOD >$GENSED
+1,$s/^\(.\).*[ ]\([0-9][0-9]*\), *\([0-9][0-9]*\)[ ].*[ ]\([^ ][^ ]*\)$/\2 \3 \1 \4/
+/:[^ ,][^ ,]*$/s/^\(.*\):\([^ ,]*\)$/\1:\2 \2/
+/:[^ ,][^ ,]*,[^ ]*$/s/^\(.*\):\([^ ,]*\),\([^ ]*\)$/\1:\2,\3 \2/
+!EOD
+
+# Next lines are generated from the "/etc/name_to_major file; they change the
+# "major number" field into its corresponding 'name'. This is so that
+# the difference in major-numbers among different machines can be hidden.
+#
+grep -v '^#' /etc/name_to_major | sed -e '1,$s-^\([^ ]*\)[ ][ ]*\([^ ][^ ]*\)$-/^\2 /s/^\2 /\1 /-' >>$GENSED
+
+#
+#----------------------------------------------------------------------
+#
+# Have finished generating sedscr. Now we generate 'nawkscr'; first we insert
+# the header ...
+
+cat >$GENAWK <<\!EOD
+BEGIN {
+!EOD
+
+# and then we find all the symbolic-links under /dev, massage the output of
+# an 'ls -l' with the sed script we generated above, and then 'nawk' the output
+# using the actual link data table script. This generates the heart of our
+# link-creating 'nawk' script.
+
+echo "Scanning /devices/ directory tree..." >&2
+
+ls -l `find ../devices \( -type b -o -type c \) -print` | sed -f $GENSED |\
+sort -b +0 -1 +1n -2 +4 -5 | nawk -f $GENRULE >>$GENAWK
+
+cat >>$GENAWK <<\!EOD
+ }
+$2 in devname {
+ if (length(devdir[$2]) <= 0)
+ next;
+ if (devdir[$2] == "./") {
+ if ($1 == devname[$2])
+ next;
+ }
+ else if (match($1, "^" devdir[$2] "[^/]*$") == 0)
+ next;
+
+ printf "rm -f %s; ln -s %s %s\n", devname[$2], $1, devname[$2];
+ if (length(devextra[$2]) > 0) {
+ printf "rm -f %s; ln -s %s %s\n", devextra[$2],
+ devname[$2], devextra[$2];
+ delete devextra[$2];
+ }
+ delete devname[$2];
+ delete devdir[$2];
+ }
+END {
+ for (dev in devname) {
+ printf "rm -f %s; ln -s %s %s\n", devname[dev],
+ substr(dev, match(dev, "\.\./devices/"), 999),
+ devname[dev];
+ if (length(devextra[dev]) > 0)
+ printf "rm -f %s; ln -s %s %s\n", devextra[dev],
+ devname[dev], devextra[dev];
+ }
+ }
+!EOD
+
+#
+#----------------------------------------------------------------------
+#
+echo "Scanning /dev/ directory tree..." >&2
+
+ls -l `find . -type l -print` |\
+ sed -e '1,$s/^.* \.\/\([^ ][^ ]*\) -> \([^ ][^ ]*\)$/\1 \2/' |\
+ nawk -f $GENAWK |\
+ $DOIT_CMD
diff --git a/usr/src/ucbcmd/users/Makefile b/usr/src/ucbcmd/users/Makefile
new file mode 100644
index 0000000000..e1c9c18914
--- /dev/null
+++ b/usr/src/ucbcmd/users/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= users
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/users/users.c b/usr/src/ucbcmd/users/users.c
new file mode 100644
index 0000000000..d4011b0ecd
--- /dev/null
+++ b/usr/src/ucbcmd/users/users.c
@@ -0,0 +1,102 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983-1998 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+/*
+ * users
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <utmpx.h>
+
+static char *strndup(char *p, int n);
+
+struct utmpx *utmpx;
+char **names;
+char **namp;
+
+main(argc, argv)
+char **argv;
+{
+ char *tp;
+ int nusers = 0;
+ int bufflen = BUFSIZ;
+
+ if (argc == 2)
+ if (!utmpxname(argv[1])) {
+ fprintf(stderr, "Filename is too long\n");
+ exit(1);
+ }
+
+ names = namp = (char **)realloc((void *)NULL, BUFSIZ * sizeof (char *));
+
+ setutxent();
+
+ while ((utmpx = getutxent()) != NULL) {
+ if (utmpx->ut_name[0] == '\0')
+ continue;
+ if (utmpx->ut_type != USER_PROCESS)
+ continue;
+ if (nonuserx(*utmpx))
+ continue;
+ if (nusers == bufflen) {
+ bufflen *= 2;
+ names = (char **)realloc(names,
+ bufflen * sizeof (char *));
+ namp = names + nusers;
+ }
+ *namp++ = strndup(utmpx->ut_name, sizeof (utmpx->ut_name));
+ nusers++;
+ }
+
+ endutxent();
+
+ summary();
+ exit(0);
+}
+
+static char *
+strndup(char *p, int n)
+{
+
+ register char *x;
+ x = malloc(n + 1);
+ strncpy(x, p, n);
+ *(x + n) = '\0';
+ return (x);
+
+}
+
+scmp(const void *p, const void *q)
+{
+ return (strcmp((char *)p, (char *)q));
+}
+
+summary()
+{
+ register char **p;
+
+ qsort(names, namp - names, sizeof (names[0]), scmp);
+ for (p = names; p < namp; p++) {
+ if (p != names)
+ putchar(' ');
+ fputs(*p, stdout);
+ }
+ if (namp != names) /* at least one user */
+ putchar('\n');
+}
diff --git a/usr/src/ucbcmd/vipw/Makefile b/usr/src/ucbcmd/vipw/Makefile
new file mode 100644
index 0000000000..1b2e183f06
--- /dev/null
+++ b/usr/src/ucbcmd/vipw/Makefile
@@ -0,0 +1,54 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= vipw
+
+include ../Makefile.ucbcmd
+
+INC1 = $(ROOT)/usr/ucbinclude
+
+#LDLIBS += -L$(ROOT)/usr/ucblib -lucb -lelf
+LDLIBS = -L$(ROOT)/usr/ucblib $(LDLIBS.cmd) -lucb
+
+#CPPFLAGS.master += -I$(INC1)
+CPPFLAGS = -I$(INC1) $(CPPFLAGS.master)
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(PROG).c
+ $(SETRUNPATH) $(LINK.c) -o $@ $(PROG).c $(LDLIBS)
+ $(POST_PROCESS)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/vipw/vipw.c b/usr/src/ucbcmd/vipw/vipw.c
new file mode 100644
index 0000000000..8caf3bedfb
--- /dev/null
+++ b/usr/src/ucbcmd/vipw/vipw.c
@@ -0,0 +1,376 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+/*
+ * Portions of this source code were derived from Berkeley 4.3 BSD
+ * under license from the Regents of the University of California.
+ */
+
+#ident "%Z%%M% %I% %E% SMI"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <sys/fcntl.h>
+
+#include <stdio.h>
+#include <errno.h>
+#include <signal.h>
+
+/*
+ * Password file editor with locking.
+ */
+
+#define DEFAULT_EDITOR "/usr/bin/vi"
+
+char *ptemp = "/etc/ptmp";
+char *stemp = "/etc/stmp";
+char *passwd = "/etc/passwd";
+char *shadow = "/etc/shadow";
+char buf[BUFSIZ];
+char *getenv();
+char *index();
+extern int errno;
+
+main()
+{
+ int fd;
+ FILE *ft, *fp;
+ char *editor;
+ int ok = 0;
+ time_t o_mtime, n_mtime;
+ struct stat osbuf, sbuf, oshdbuf, shdbuf;
+ char c;
+
+ (void)signal(SIGINT, SIG_IGN);
+ (void)signal(SIGQUIT, SIG_IGN);
+ (void)signal(SIGHUP, SIG_IGN);
+ setbuf(stderr, (char *)NULL);
+
+ editor = getenv("VISUAL");
+ if (editor == 0)
+ editor = getenv("EDITOR");
+ if (editor == 0)
+ editor = DEFAULT_EDITOR;
+
+ (void)umask(0077);
+ if (stat(passwd, &osbuf) < 0) {
+ (void)fprintf(stderr,"vipw: can't stat passwd file.\n");
+ goto bad;
+ }
+
+ if (copyfile(passwd, ptemp))
+ goto bad;
+
+ if (stat(ptemp, &sbuf) < 0) {
+ (void)fprintf(stderr,
+ "vipw: can't stat ptemp file, %s unchanged\n",
+ passwd);
+ goto bad;
+ }
+
+ o_mtime = sbuf.st_mtime;
+
+ if (editfile(editor, ptemp, passwd, &n_mtime)) {
+ if (sanity_check(ptemp, &n_mtime, passwd))
+ goto bad;
+ if (o_mtime >= n_mtime)
+ goto bad;
+ }
+
+ ok++;
+ if (o_mtime < n_mtime) {
+ fprintf(stdout, "\nYou have modified the password file.\n");
+ fprintf(stdout,
+ "Press 'e' to edit the shadow file for consistency,\n 'q' to quit: ");
+ if ((c = getchar()) == 'q') {
+ if (chmod(ptemp, (osbuf.st_mode & 0644)) < 0) {
+ (void) fprintf(stderr, "vipw: %s: ", ptemp);
+ perror("chmod");
+ goto bad;
+ }
+ if (rename(ptemp, passwd) < 0) {
+ (void) fprintf(stderr, "vipw: %s: ", ptemp);
+ perror("rename");
+ goto bad;
+ }
+ if (((osbuf.st_gid != sbuf.st_gid) ||
+ (osbuf.st_uid != sbuf.st_uid)) &&
+ (chown(passwd, osbuf.st_uid, osbuf.st_gid) < 0)) {
+ (void) fprintf(stderr, "vipw: %s ", ptemp);
+ perror("chown");
+ }
+ goto bad;
+ } else if (c == 'e') {
+ if (stat(shadow, &oshdbuf) < 0) {
+ (void) fprintf(stderr,
+ "vipw: can't stat shadow file.\n");
+ goto bad;
+ }
+
+ if (copyfile(shadow, stemp))
+ goto bad;
+ if (stat(stemp, &shdbuf) < 0) {
+ (void) fprintf(stderr,
+ "vipw: can't stat stmp file.\n");
+ goto bad;
+ }
+
+ if (editfile(editor, stemp, shadow, &o_mtime))
+ goto bad;
+ ok++;
+ if (chmod(ptemp, (osbuf.st_mode & 0644)) < 0) {
+ (void) fprintf(stderr, "vipw: %s: ", ptemp);
+ perror("chmod");
+ goto bad;
+ }
+ if (chmod(stemp, (oshdbuf.st_mode & 0400)) < 0) {
+ (void) fprintf(stderr, "vipw: %s: ", stemp);
+ perror("chmod");
+ goto bad;
+ }
+ if (rename(ptemp, passwd) < 0) {
+ (void) fprintf(stderr, "vipw: %s: ", ptemp);
+ perror("rename");
+ goto bad;
+ }
+ if (((osbuf.st_gid != sbuf.st_gid) ||
+ (osbuf.st_uid != sbuf.st_uid)) &&
+ (chown(passwd, osbuf.st_uid, osbuf.st_gid) < 0)) {
+ (void) fprintf(stderr, "vipw: %s ", ptemp);
+ perror("chown");
+ }
+ if (rename(stemp, shadow) < 0) {
+ (void) fprintf(stderr, "vipw: %s: ", stemp);
+ perror("rename");
+ goto bad;
+ } else if (((oshdbuf.st_gid != shdbuf.st_gid) ||
+ (oshdbuf.st_uid != shdbuf.st_uid)) &&
+ (chown(shadow, oshdbuf.st_uid, oshdbuf.st_gid) < 0)) {
+ (void) fprintf(stderr, "vipw: %s ", stemp);
+ perror("chown");
+ }
+ }
+ }
+bad:
+ (void) unlink(ptemp);
+ (void) unlink(stemp);
+ exit(ok ? 0 : 1);
+ /* NOTREACHED */
+}
+
+
+copyfile(from, to)
+char *from, *to;
+{
+ int fd;
+ FILE *fp, *ft;
+
+ fd = open(to, O_WRONLY|O_CREAT|O_EXCL, 0600);
+ if (fd < 0) {
+ if (errno == EEXIST) {
+ (void) fprintf(stderr, "vipw: %s file busy\n", from);
+ exit(1);
+ }
+ (void) fprintf(stderr, "vipw: "); perror(to);
+ exit(1);
+ }
+ ft = fdopen(fd, "w");
+ if (ft == NULL) {
+ (void) fprintf(stderr, "vipw: "); perror(to);
+ return( 1 );
+ }
+ fp = fopen(from, "r");
+ if (fp == NULL) {
+ (void) fprintf(stderr, "vipw: "); perror(from);
+ return( 1 );
+ }
+ while (fgets(buf, sizeof (buf) - 1, fp) != NULL)
+ fputs(buf, ft);
+ (void) fclose(ft);
+ (void) fclose(fp);
+ return( 0 );
+}
+
+editfile(editor, temp, orig, mtime)
+char *editor, *temp, *orig;
+time_t *mtime;
+{
+
+ (void)sprintf(buf, "%s %s", editor, temp);
+ if (system(buf) == 0) {
+ return (sanity_check(temp, mtime, orig));
+ }
+ return(1);
+}
+
+
+validsh(rootsh)
+ char *rootsh;
+{
+
+ char *sh, *getusershell();
+ int ret = 0;
+
+ setusershell();
+ while((sh = getusershell()) != NULL ) {
+ if( strcmp( rootsh, sh) == 0 ) {
+ ret = 1;
+ break;
+ }
+ }
+ endusershell();
+ return(ret);
+}
+
+/*
+ * sanity checks
+ * return 0 if ok, 1 otherwise
+ */
+sanity_check(temp, mtime, orig)
+char *temp, *orig;
+time_t *mtime;
+{
+ int i, ok = 0;
+ FILE *ft;
+ struct stat sbuf;
+ int isshadow = 0;
+
+ if (!strcmp(orig, shadow))
+ isshadow = 1;
+
+ /* sanity checks */
+ if (stat(temp, &sbuf) < 0) {
+ (void)fprintf(stderr,
+ "vipw: can't stat %s file, %s unchanged\n",
+ temp, orig);
+ return(1);
+ }
+ *mtime = sbuf.st_mtime;
+ if (sbuf.st_size == 0) {
+ (void)fprintf(stderr, "vipw: bad %s file, %s unchanged\n",
+ temp, orig);
+ return(1);
+ }
+ ft = fopen(temp, "r");
+ if (ft == NULL) {
+ (void)fprintf(stderr,
+ "vipw: can't reopen %s file, %s unchanged\n",
+ temp, orig);
+ return(1);
+ }
+
+ while (fgets(buf, sizeof (buf) - 1, ft) != NULL) {
+ register char *cp;
+
+ cp = index(buf, '\n');
+ if (cp == 0)
+ continue; /* ??? allow very long lines
+ * and passwd files that do
+ * not end in '\n' ???
+ */
+ *cp = '\0';
+
+ cp = index(buf, ':');
+ if (cp == 0) /* lines without colon
+ * separated fields
+ */
+ continue;
+ *cp = '\0';
+
+ if (strcmp(buf, "root"))
+ continue;
+
+ /* root password */
+ *cp = ':';
+ cp = index(cp + 1, ':');
+ if (cp == 0)
+ goto bad_root;
+
+ /* root uid for password */
+ if (!isshadow)
+ if (atoi(cp + 1) != 0) {
+
+ (void)fprintf(stderr, "root UID != 0:\n%s\n",
+ buf);
+ break;
+ }
+ /* root uid for passwd and sp_lstchg for shadow */
+ cp = index(cp + 1, ':');
+ if (cp == 0)
+ goto bad_root;
+
+ /* root's gid for passwd and sp_min for shadow*/
+ cp = index(cp + 1, ':');
+ if (cp == 0)
+ goto bad_root;
+
+ /* root's gecos for passwd and sp_max for shadow*/
+ cp = index(cp + 1, ':');
+ if (isshadow) {
+ for (i=0; i<3; i++)
+ if ((cp = index(cp + 1, ':')) == 0)
+ goto bad_root;
+ } else {
+ if (cp == 0) {
+bad_root: (void)fprintf(stderr,
+ "Missing fields in root entry:\n%s\n", buf);
+ break;
+ }
+ }
+ if (!isshadow) {
+ /* root's login directory */
+ if (strncmp(++cp, "/:", 2)) {
+ (void)fprintf(stderr,
+ "Root login directory != \"/\" or%s\n%s\n",
+ " default shell missing:", buf);
+ break;
+ }
+
+ /* root's login shell */
+ cp += 2;
+ if (*cp && ! validsh(cp)) {
+ (void)fprintf(stderr,
+ "Invalid root shell:\n%s\n", buf);
+ break;
+ }
+ }
+
+ ok++;
+ }
+ (void)fclose(ft);
+ if (ok)
+ return(0);
+ else {
+ (void)fprintf(stderr,
+ "vipw: you mangled the %s file, %s unchanged\n",
+ temp, orig);
+ return(1);
+ }
+}
diff --git a/usr/src/ucbcmd/whereis/Makefile b/usr/src/ucbcmd/whereis/Makefile
new file mode 100644
index 0000000000..c34916c983
--- /dev/null
+++ b/usr/src/ucbcmd/whereis/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright (c) 1989 by Sun Microsystems, Inc.
+#
+
+PROG= whereis
+
+include ../Makefile.ucbcmd
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/whereis/whereis.c b/usr/src/ucbcmd/whereis/whereis.c
new file mode 100644
index 0000000000..f2cf33b972
--- /dev/null
+++ b/usr/src/ucbcmd/whereis/whereis.c
@@ -0,0 +1,348 @@
+/*
+ * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+
+#include <sys/param.h>
+#include <dirent.h>
+#include <stdio.h>
+#include <ctype.h>
+
+static char *bindirs[] = {
+ "/etc",
+ "/sbin",
+ "/usr/bin",
+ "/usr/ccs/bin",
+ "/usr/ccs/lib",
+ "/usr/lang",
+ "/usr/lbin",
+ "/usr/lib",
+ "/usr/sbin",
+ "/usr/ucb",
+ "/usr/ucblib",
+ "/usr/ucbinclude",
+ "/usr/games",
+ "/usr/local",
+ "/usr/local/bin",
+ "/usr/new",
+ "/usr/old",
+ "/usr/hosts",
+ "/usr/include",
+ "/usr/etc",
+ 0
+};
+static char *mandirs[] = {
+ "/usr/man/man1",
+ "/usr/man/man1b",
+ "/usr/man/man1c",
+ "/usr/man/man1f",
+ "/usr/man/man1m",
+ "/usr/man/man1s",
+ "/usr/man/man2",
+ "/usr/man/man3",
+ "/usr/man/man3b",
+ "/usr/man/man3c",
+ "/usr/man/man3e",
+ "/usr/man/man3g",
+ "/usr/man/man3j",
+ "/usr/man/man3k",
+ "/usr/man/man3l",
+ "/usr/man/man3m",
+ "/usr/man/man3n",
+ "/usr/man/man3s",
+ "/usr/man/man3w",
+ "/usr/man/man3x",
+ "/usr/man/man3x11",
+ "/usr/man/man3xt",
+ "/usr/man/man4",
+ "/usr/man/man4b",
+ "/usr/man/man5",
+ "/usr/man/man6",
+ "/usr/man/man7",
+ "/usr/man/man7b",
+ "/usr/man/man8",
+ "/usr/man/man9e",
+ "/usr/man/man9f",
+ "/usr/man/man9s",
+ "/usr/man/manl",
+ "/usr/man/mann",
+ "/usr/man/mano",
+ 0
+};
+static char *srcdirs[] = {
+ "/usr/src/cmd",
+ "/usr/src/head",
+ "/usr/src/lib",
+ "/usr/src/lib/libc",
+ "/usr/src/lib/libc/port",
+ "/usr/src/lib/libc/port/gen",
+ "/usr/src/lib/libc/port/print",
+ "/usr/src/lib/libc/port/stdio",
+ "/usr/src/lib/libc/port/sys",
+ "/usr/src/lib/libc/sparc",
+ "/usr/src/lib/libc/sparc/gen",
+ "/usr/src/lib/libc/sparc/sys",
+ "/usr/src/ucbcmd",
+ "/usr/src/ucblib",
+ "/usr/src/ucbinclude",
+ "/usr/src/uts",
+ "/usr/src/uts/common",
+ "/usr/src/uts/sun",
+ "/usr/src/uts/sun4",
+ "/usr/src/uts/sun4c",
+ "/usr/src/uts/sparc",
+ "/usr/src/local",
+ "/usr/src/new",
+ "/usr/src/old",
+ 0
+};
+
+char sflag = 1;
+char bflag = 1;
+char mflag = 1;
+char **Sflag;
+int Scnt;
+char **Bflag;
+int Bcnt;
+char **Mflag;
+int Mcnt;
+char uflag;
+/*
+ * whereis name
+ * look for source, documentation and binaries
+ */
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+
+ argc--, argv++;
+ if (argc == 0) {
+usage:
+ fprintf(stderr, "whereis [ -sbmu ] [ -SBM dir ... -f ] name...\n");
+ exit(1);
+ }
+ do
+ if (argv[0][0] == '-') {
+ register char *cp = argv[0] + 1;
+ while (*cp) switch (*cp++) {
+
+ case 'f':
+ break;
+
+ case 'S':
+ getlist(&argc, &argv, &Sflag, &Scnt);
+ break;
+
+ case 'B':
+ getlist(&argc, &argv, &Bflag, &Bcnt);
+ break;
+
+ case 'M':
+ getlist(&argc, &argv, &Mflag, &Mcnt);
+ break;
+
+ case 's':
+ zerof();
+ sflag++;
+ continue;
+
+ case 'u':
+ uflag++;
+ continue;
+
+ case 'b':
+ zerof();
+ bflag++;
+ continue;
+
+ case 'm':
+ zerof();
+ mflag++;
+ continue;
+
+ default:
+ goto usage;
+ }
+ argv++;
+ } else
+ lookup(*argv++);
+ while (--argc > 0);
+ exit(0);
+ /* NOTREACHED */
+}
+
+getlist(argcp, argvp, flagp, cntp)
+ char ***argvp;
+ int *argcp;
+ char ***flagp;
+ int *cntp;
+{
+
+ (*argvp)++;
+ *flagp = *argvp;
+ *cntp = 0;
+ for ((*argcp)--; *argcp > 0 && (*argvp)[0][0] != '-'; (*argcp)--)
+ (*cntp)++, (*argvp)++;
+ (*argcp)++;
+ (*argvp)--;
+}
+
+
+zerof()
+{
+
+ if (sflag && bflag && mflag)
+ sflag = bflag = mflag = 0;
+}
+int count;
+int print;
+
+
+lookup(cp)
+ register char *cp;
+{
+ register char *dp;
+
+ for (dp = cp; *dp; dp++)
+ continue;
+ for (; dp > cp; dp--) {
+ if (*dp == '.') {
+ *dp = 0;
+ break;
+ }
+ }
+ for (dp = cp; *dp; dp++)
+ if (*dp == '/')
+ cp = dp + 1;
+ if (uflag) {
+ print = 0;
+ count = 0;
+ } else
+ print = 1;
+again:
+ if (print)
+ printf("%s:", cp);
+ if (sflag) {
+ looksrc(cp);
+ if (uflag && print == 0 && count != 1) {
+ print = 1;
+ goto again;
+ }
+ }
+ count = 0;
+ if (bflag) {
+ lookbin(cp);
+ if (uflag && print == 0 && count != 1) {
+ print = 1;
+ goto again;
+ }
+ }
+ count = 0;
+ if (mflag) {
+ lookman(cp);
+ if (uflag && print == 0 && count != 1) {
+ print = 1;
+ goto again;
+ }
+ }
+ if (print)
+ printf("\n");
+}
+
+looksrc(cp)
+ char *cp;
+{
+ if (Sflag == 0) {
+ find(srcdirs, cp);
+ } else
+ findv(Sflag, Scnt, cp);
+}
+
+lookbin(cp)
+ char *cp;
+{
+ if (Bflag == 0)
+ find(bindirs, cp);
+ else
+ findv(Bflag, Bcnt, cp);
+}
+
+lookman(cp)
+ char *cp;
+{
+ if (Mflag == 0) {
+ find(mandirs, cp);
+ } else
+ findv(Mflag, Mcnt, cp);
+}
+
+findv(dirv, dirc, cp)
+ char **dirv;
+ int dirc;
+ char *cp;
+{
+
+ while (dirc > 0)
+ findin(*dirv++, cp), dirc--;
+}
+
+find(dirs, cp)
+ char **dirs;
+ char *cp;
+{
+
+ while (*dirs)
+ findin(*dirs++, cp);
+}
+
+findin(dir, cp)
+ char *dir, *cp;
+{
+ DIR *dirp;
+ struct dirent *dp;
+
+ dirp = opendir(dir);
+ if (dirp == NULL)
+ return;
+ while ((dp = readdir(dirp)) != NULL) {
+ if (itsit(cp, dp->d_name)) {
+ count++;
+ if (print)
+ printf(" %s/%s", dir, dp->d_name);
+ }
+ }
+ closedir(dirp);
+}
+
+itsit(cp, dp)
+ register char *cp, *dp;
+{
+ register int i = strlen(dp);
+
+ if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp+2))
+ return (1);
+ while (*cp && *dp && *cp == *dp)
+ cp++, dp++, i--;
+ if (*cp == 0 && *dp == 0)
+ return (1);
+ while (isdigit(*dp))
+ dp++;
+ if (*cp == 0 && *dp++ == '.') {
+ --i;
+ while (i > 0 && *dp)
+ if (--i, *dp++ == '.')
+ return (*dp++ == 'C' && *dp++ == 0);
+ return (1);
+ }
+ return (0);
+}
diff --git a/usr/src/ucbcmd/whoami/Makefile b/usr/src/ucbcmd/whoami/Makefile
new file mode 100644
index 0000000000..02cb1a6811
--- /dev/null
+++ b/usr/src/ucbcmd/whoami/Makefile
@@ -0,0 +1,50 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+PROG= whoami
+
+include ../Makefile.ucbcmd
+
+CFLAGS += $(CCVERBOSE)
+
+XGETFLAGS += -a -x rmdir.xcl
+
+
+FILEMODE= 755
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.ucbtarg
diff --git a/usr/src/ucbcmd/whoami/whoami.c b/usr/src/ucbcmd/whoami/whoami.c
new file mode 100644
index 0000000000..a13ca2b973
--- /dev/null
+++ b/usr/src/ucbcmd/whoami/whoami.c
@@ -0,0 +1,54 @@
+/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
+/* All Rights Reserved */
+
+
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+/*
+ * Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
+ * All Rights Reserved.
+ */
+
+#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
+
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <locale.h>
+#include <stdlib.h>
+
+#define MSG "whoami: no login associated with uid %u.\n"
+
+/*
+ * whoami
+ */
+struct passwd *getpwuid();
+
+void
+main()
+{
+ register struct passwd *pp;
+ uid_t euid;
+
+ /* Set locale environment variables local definitions */
+ (void) setlocale(LC_ALL, "");
+#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
+#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ euid = geteuid();
+ pp = getpwuid(euid);
+ if (pp == 0) {
+ (void) printf(gettext(MSG), euid);
+ exit(1);
+ }
+ printf("%s\n", pp->pw_name);
+ exit(0);
+ /*NOTREACHED*/
+}