From 44bd5ea795281151bc7b81a65d2dd42c6b8914d8 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 10 Apr 2001 15:59:39 +0000 Subject: [PATCH] shell_cmds-17.1.tar.gz --- Makefile | 53 ++ Makefile.postamble | 1 + Makefile.preamble | 1 + PB.project | 67 ++ PROJECT | 12 + apply/Makefile | 48 ++ apply/Makefile.postamble | 1 + apply/Makefile.preamble | 1 + apply/PB.project | 27 + apply/apply.1 | 135 ++++ apply/apply.c | 243 ++++++ basename/Makefile | 49 ++ basename/Makefile.postamble | 1 + basename/Makefile.preamble | 1 + basename/PB.project | 27 + basename/basename.1 | 94 +++ basename/basename.c | 148 ++++ basename/dirname.1 | 1 + chroot/Makefile | 48 ++ chroot/Makefile.postamble | 1 + chroot/Makefile.preamble | 1 + chroot/PB.project | 27 + chroot/chroot.8 | 102 +++ chroot/chroot.c | 178 +++++ date/Makefile | 50 ++ date/Makefile.postamble | 1 + date/Makefile.preamble | 1 + date/PB.project | 28 + date/date.1 | 213 ++++++ date/date.c | 244 ++++++ date/extern.h | 38 + date/netdate.c | 195 +++++ dirname/Makefile | 48 ++ dirname/Makefile.postamble | 1 + dirname/Makefile.preamble | 1 + dirname/PB.project | 27 + dirname/dirname.c | 155 ++++ echo/Makefile | 48 ++ echo/Makefile.postamble | 1 + echo/Makefile.preamble | 1 + echo/PB.project | 27 + echo/echo.1 | 72 ++ echo/echo.c | 82 +++ env/Makefile | 48 ++ env/Makefile.postamble | 1 + env/Makefile.preamble | 1 + env/PB.project | 27 + env/env.1 | 125 ++++ env/env.c | 104 +++ expr/Makefile | 48 ++ expr/Makefile.postamble | 1 + expr/Makefile.preamble | 1 + expr/PB.project | 27 + expr/expr.1 | 105 +++ expr/expr.c | 548 ++++++++++++++ false/Makefile | 48 ++ false/Makefile.postamble | 1 + false/Makefile.preamble | 1 + false/PB.project | 27 + false/false.1 | 60 ++ false/false.c | 1 + find/Makefile | 50 ++ find/Makefile.postamble | 1 + find/Makefile.preamble | 1 + find/PB.project | 27 + find/extern.h | 83 +++ find/find.1 | 482 ++++++++++++ find/find.c | 211 ++++++ find/find.h | 106 +++ find/function.c | 1187 ++++++++++++++++++++++++++++++ find/ls.c | 131 ++++ find/main.c | 158 ++++ find/misc.c | 135 ++++ find/operator.c | 279 +++++++ find/option.c | 144 ++++ getopt/Makefile | 48 ++ getopt/Makefile.postamble | 1 + getopt/Makefile.preamble | 1 + getopt/PB.project | 27 + getopt/getopt.1 | 121 +++ getopt/getopt.c | 40 + hostname/Makefile | 49 ++ hostname/Makefile.postamble | 1 + hostname/Makefile.preamble | 1 + hostname/PB.project | 28 + hostname/hostname.1 | 69 ++ hostname/hostname.c | 107 +++ id/Makefile | 50 ++ id/Makefile.postamble | 5 + id/Makefile.preamble | 1 + id/PB.project | 28 + id/groups.1 | 66 ++ id/id.1 | 141 ++++ id/id.c | 345 +++++++++ id/whoami.1 | 64 ++ jot/Makefile | 48 ++ jot/Makefile.postamble | 1 + jot/Makefile.preamble | 1 + jot/PB.project | 27 + jot/jot.1 | 201 +++++ jot/jot.c | 399 ++++++++++ kill/Makefile | 48 ++ kill/Makefile.postamble | 1 + kill/Makefile.preamble | 1 + kill/PB.project | 27 + kill/kill.1 | 144 ++++ kill/kill.c | 196 +++++ lastcomm/Makefile | 50 ++ lastcomm/Makefile.postamble | 1 + lastcomm/Makefile.preamble | 1 + lastcomm/PB.project | 27 + lastcomm/lastcomm.1 | 128 ++++ lastcomm/lastcomm.c | 240 ++++++ lastcomm/pathnames.h | 40 + locate/Makefile | 48 ++ locate/Makefile.postamble | 1 + locate/Makefile.preamble | 1 + locate/PB.project | 27 + locate/bigram/Makefile | 48 ++ locate/bigram/Makefile.postamble | 1 + locate/bigram/Makefile.preamble | 1 + locate/bigram/PB.project | 27 + locate/bigram/locate.bigram.c | 95 +++ locate/code/Makefile | 49 ++ locate/code/Makefile.postamble | 1 + locate/code/Makefile.preamble | 1 + locate/code/PB.project | 28 + locate/code/locate.code.c | 220 ++++++ locate/locate/Makefile | 51 ++ locate/locate/Makefile.postamble | 5 + locate/locate/Makefile.preamble | 1 + locate/locate/PB.project | 27 + locate/locate/locate.1 | 87 +++ locate/locate/locate.c | 206 ++++++ locate/locate/locate.h | 43 ++ locate/locate/pathnames.h | 38 + locate/locate/updatedb.csh | 81 ++ logname/Makefile | 48 ++ logname/Makefile.postamble | 1 + logname/Makefile.preamble | 1 + logname/PB.project | 27 + logname/logname.1 | 78 ++ logname/logname.c | 92 +++ nice/Makefile | 48 ++ nice/Makefile.postamble | 1 + nice/Makefile.preamble | 1 + nice/PB.project | 27 + nice/nice.1 | 120 +++ nice/nice.c | 122 +++ nohup/Makefile | 48 ++ nohup/Makefile.postamble | 1 + nohup/Makefile.preamble | 1 + nohup/PB.project | 27 + nohup/nohup.1 | 105 +++ nohup/nohup.c | 143 ++++ printenv/Makefile | 48 ++ printenv/Makefile.postamble | 1 + printenv/Makefile.preamble | 1 + printenv/PB.project | 27 + printenv/printenv.1 | 69 ++ printenv/printenv.c | 104 +++ printf/Makefile | 48 ++ printf/Makefile.postamble | 1 + printf/Makefile.preamble | 1 + printf/PB.project | 27 + printf/printf.1 | 280 +++++++ printf/printf.c | 550 ++++++++++++++ pwd/Makefile | 48 ++ pwd/Makefile.postamble | 1 + pwd/Makefile.preamble | 1 + pwd/PB.project | 27 + pwd/pwd.1 | 83 +++ pwd/pwd.c | 160 ++++ renice/Makefile | 48 ++ renice/Makefile.postamble | 1 + renice/Makefile.preamble | 1 + renice/PB.project | 27 + renice/renice.8 | 135 ++++ renice/renice.c | 135 ++++ script/Makefile | 48 ++ script/Makefile.postamble | 1 + script/Makefile.preamble | 1 + script/PB.project | 27 + script/script.1 | 126 ++++ script/script.c | 249 +++++++ shlock/Makefile | 48 ++ shlock/Makefile.postamble | 1 + shlock/Makefile.preamble | 1 + shlock/PB.project | 27 + shlock/shlock.1 | 122 +++ shlock/shlock.c | 344 +++++++++ sleep/Makefile | 48 ++ sleep/Makefile.postamble | 1 + sleep/Makefile.preamble | 1 + sleep/PB.project | 27 + sleep/sleep.1 | 124 ++++ sleep/sleep.c | 154 ++++ su/Makefile | 48 ++ su/Makefile.postamble | 5 + su/Makefile.preamble | 1 + su/PB.project | 27 + su/su.1 | 186 +++++ su/su.c | 504 +++++++++++++ tee/Makefile | 48 ++ tee/Makefile.postamble | 1 + tee/Makefile.preamble | 1 + tee/PB.project | 27 + tee/tee.1 | 90 +++ tee/tee.c | 156 ++++ test/Makefile | 49 ++ test/Makefile.postamble | 6 + test/Makefile.preamble | 1 + test/PB.project | 27 + test/TEST.csh | 138 ++++ test/[.1 | 1 + test/test.1 | 317 ++++++++ test/test.c | 468 ++++++++++++ time/Makefile | 48 ++ time/Makefile.postamble | 1 + time/Makefile.preamble | 1 + time/PB.project | 27 + time/time.1 | 123 ++++ time/time.c | 173 +++++ true/Makefile | 48 ++ true/Makefile.postamble | 1 + true/Makefile.preamble | 1 + true/PB.project | 27 + true/true.1 | 60 ++ true/true.c | 1 + uname/Makefile | 48 ++ uname/Makefile.postamble | 1 + uname/Makefile.preamble | 1 + uname/PB.project | 27 + uname/uname.1 | 88 +++ uname/uname.c | 168 +++++ users/Makefile | 48 ++ users/Makefile.postamble | 1 + users/Makefile.preamble | 1 + users/PB.project | 27 + users/users.1 | 61 ++ users/users.c | 125 ++++ w/Makefile | 51 ++ w/Makefile.postamble | 7 + w/Makefile.preamble | 1 + w/PB.project | 28 + w/extern.h | 43 ++ w/fmt.c | 56 ++ w/pr_time.c | 116 +++ w/proc_compare.c | 127 ++++ w/uptime.1 | 62 ++ w/w.1 | 143 ++++ w/w.c | 476 ++++++++++++ whereis/Makefile | 48 ++ whereis/Makefile.postamble | 1 + whereis/Makefile.preamble | 1 + whereis/PB.project | 27 + whereis/whereis.1 | 66 ++ whereis/whereis.c | 128 ++++ which/Makefile | 49 ++ which/Makefile.postamble | 1 + which/Makefile.preamble | 3 + which/PB.project | 27 + which/which.1 | 75 ++ which/which.csh | 75 ++ who/Makefile | 48 ++ who/Makefile.postamble | 1 + who/Makefile.preamble | 1 + who/PB.project | 27 + who/who.1 | 134 ++++ who/who.c | 273 +++++++ window/Makefile | 66 ++ window/Makefile.postamble | 1 + window/Makefile.preamble | 1 + window/PB.project | 131 ++++ window/README | 199 +++++ window/alias.h | 58 ++ window/char.c | 157 ++++ window/char.h | 66 ++ window/cmd.c | 316 ++++++++ window/cmd1.c | 182 +++++ window/cmd2.c | 167 +++++ window/cmd3.c | 74 ++ window/cmd4.c | 64 ++ window/cmd5.c | 142 ++++ window/cmd6.c | 119 +++ window/cmd7.c | 294 ++++++++ window/compress.c | 940 +++++++++++++++++++++++ window/context.c | 147 ++++ window/context.h | 89 +++ window/defs.h | 131 ++++ window/error.c | 123 ++++ window/lcmd.c | 139 ++++ window/lcmd.h | 87 +++ window/lcmd1.c | 466 ++++++++++++ window/lcmd2.c | 408 ++++++++++ window/local.h | 53 ++ window/main.c | 207 ++++++ window/mloop.c | 96 +++ window/parser.h | 65 ++ window/parser1.c | 249 +++++++ window/parser2.c | 247 +++++++ window/parser3.c | 203 +++++ window/parser4.c | 307 ++++++++ window/parser5.c | 211 ++++++ window/scanner.c | 598 +++++++++++++++ window/startup.c | 104 +++ window/string.c | 165 +++++ window/token.h | 85 +++ window/tt.h | 183 +++++ window/ttf100.c | 77 ++ window/ttgeneric.c | 615 ++++++++++++++++ window/tth19.c | 322 ++++++++ window/tth29.c | 105 +++ window/ttinit.c | 120 +++ window/ttoutput.c | 157 ++++ window/tttermcap.c | 135 ++++ window/tttvi925.c | 72 ++ window/ttwyse60.c | 84 +++ window/ttwyse75.c | 84 +++ window/ttzapple.c | 552 ++++++++++++++ window/ttzentec.c | 74 ++ window/value.h | 55 ++ window/var.c | 168 +++++ window/var.h | 67 ++ window/win.c | 396 ++++++++++ window/window.1 | 949 ++++++++++++++++++++++++ window/window_string.h | 79 ++ window/windowrc | 85 +++ window/ww.h | 399 ++++++++++ window/wwadd.c | 96 +++ window/wwalloc.c | 82 +++ window/wwbox.c | 74 ++ window/wwchild.c | 79 ++ window/wwclose.c | 69 ++ window/wwclreol.c | 104 +++ window/wwclreos.c | 64 ++ window/wwcursor.c | 103 +++ window/wwdata.c | 46 ++ window/wwdelchar.c | 133 ++++ window/wwdelete.c | 149 ++++ window/wwdelline.c | 96 +++ window/wwdump.c | 128 ++++ window/wwend.c | 75 ++ window/wwenviron.c | 117 +++ window/wwerror.c | 75 ++ window/wwflush.c | 127 ++++ window/wwframe.c | 255 +++++++ window/wwgets.c | 120 +++ window/wwinit.c | 425 +++++++++++ window/wwinschar.c | 140 ++++ window/wwinsline.c | 96 +++ window/wwiomux.c | 209 ++++++ window/wwlabel.c | 106 +++ window/wwmisc.c | 76 ++ window/wwmove.c | 107 +++ window/wwopen.c | 206 ++++++ window/wwprintf.c | 80 ++ window/wwpty.c | 97 +++ window/wwputc.c | 56 ++ window/wwputs.c | 60 ++ window/wwredraw.c | 65 ++ window/wwredrawwin.c | 81 ++ window/wwrint.c | 87 +++ window/wwscroll.c | 244 ++++++ window/wwsize.c | 201 +++++ window/wwspawn.c | 103 +++ window/wwsuspend.c | 64 ++ window/wwterminfo.c | 127 ++++ window/wwtty.c | 195 +++++ window/wwunframe.c | 84 +++ window/wwupdate.c | 281 +++++++ window/wwwrite.c | 313 ++++++++ window/xx.c | 287 ++++++++ window/xx.h | 81 ++ window/xxflush.c | 205 ++++++ xargs/Makefile | 50 ++ xargs/Makefile.postamble | 1 + xargs/Makefile.preamble | 1 + xargs/PB.project | 27 + xargs/pathnames.h | 38 + xargs/xargs.1 | 192 +++++ xargs/xargs.c | 344 +++++++++ yes/Makefile | 48 ++ yes/Makefile.postamble | 1 + yes/Makefile.preamble | 1 + yes/PB.project | 27 + yes/yes.1 | 56 ++ yes/yes.c | 63 ++ 388 files changed, 38750 insertions(+) create mode 100644 Makefile create mode 100644 Makefile.postamble create mode 100644 Makefile.preamble create mode 100644 PB.project create mode 100644 PROJECT create mode 100644 apply/Makefile create mode 100644 apply/Makefile.postamble create mode 100644 apply/Makefile.preamble create mode 100644 apply/PB.project create mode 100644 apply/apply.1 create mode 100644 apply/apply.c create mode 100644 basename/Makefile create mode 100644 basename/Makefile.postamble create mode 100644 basename/Makefile.preamble create mode 100644 basename/PB.project create mode 100644 basename/basename.1 create mode 100644 basename/basename.c create mode 100644 basename/dirname.1 create mode 100644 chroot/Makefile create mode 100644 chroot/Makefile.postamble create mode 100644 chroot/Makefile.preamble create mode 100644 chroot/PB.project create mode 100644 chroot/chroot.8 create mode 100644 chroot/chroot.c create mode 100644 date/Makefile create mode 100644 date/Makefile.postamble create mode 100644 date/Makefile.preamble create mode 100644 date/PB.project create mode 100644 date/date.1 create mode 100644 date/date.c create mode 100644 date/extern.h create mode 100644 date/netdate.c create mode 100644 dirname/Makefile create mode 100644 dirname/Makefile.postamble create mode 100644 dirname/Makefile.preamble create mode 100644 dirname/PB.project create mode 100644 dirname/dirname.c create mode 100644 echo/Makefile create mode 100644 echo/Makefile.postamble create mode 100644 echo/Makefile.preamble create mode 100644 echo/PB.project create mode 100644 echo/echo.1 create mode 100644 echo/echo.c create mode 100644 env/Makefile create mode 100644 env/Makefile.postamble create mode 100644 env/Makefile.preamble create mode 100644 env/PB.project create mode 100644 env/env.1 create mode 100644 env/env.c create mode 100644 expr/Makefile create mode 100644 expr/Makefile.postamble create mode 100644 expr/Makefile.preamble create mode 100644 expr/PB.project create mode 100644 expr/expr.1 create mode 100644 expr/expr.c create mode 100644 false/Makefile create mode 100644 false/Makefile.postamble create mode 100644 false/Makefile.preamble create mode 100644 false/PB.project create mode 100644 false/false.1 create mode 100644 false/false.c create mode 100644 find/Makefile create mode 100644 find/Makefile.postamble create mode 100644 find/Makefile.preamble create mode 100644 find/PB.project create mode 100644 find/extern.h create mode 100644 find/find.1 create mode 100644 find/find.c create mode 100644 find/find.h create mode 100644 find/function.c create mode 100644 find/ls.c create mode 100644 find/main.c create mode 100644 find/misc.c create mode 100644 find/operator.c create mode 100644 find/option.c create mode 100644 getopt/Makefile create mode 100644 getopt/Makefile.postamble create mode 100644 getopt/Makefile.preamble create mode 100644 getopt/PB.project create mode 100644 getopt/getopt.1 create mode 100644 getopt/getopt.c create mode 100644 hostname/Makefile create mode 100644 hostname/Makefile.postamble create mode 100644 hostname/Makefile.preamble create mode 100644 hostname/PB.project create mode 100644 hostname/hostname.1 create mode 100644 hostname/hostname.c create mode 100644 id/Makefile create mode 100644 id/Makefile.postamble create mode 100644 id/Makefile.preamble create mode 100644 id/PB.project create mode 100644 id/groups.1 create mode 100644 id/id.1 create mode 100644 id/id.c create mode 100644 id/whoami.1 create mode 100644 jot/Makefile create mode 100644 jot/Makefile.postamble create mode 100644 jot/Makefile.preamble create mode 100644 jot/PB.project create mode 100644 jot/jot.1 create mode 100644 jot/jot.c create mode 100644 kill/Makefile create mode 100644 kill/Makefile.postamble create mode 100644 kill/Makefile.preamble create mode 100644 kill/PB.project create mode 100644 kill/kill.1 create mode 100644 kill/kill.c create mode 100644 lastcomm/Makefile create mode 100644 lastcomm/Makefile.postamble create mode 100644 lastcomm/Makefile.preamble create mode 100644 lastcomm/PB.project create mode 100644 lastcomm/lastcomm.1 create mode 100644 lastcomm/lastcomm.c create mode 100644 lastcomm/pathnames.h create mode 100644 locate/Makefile create mode 100644 locate/Makefile.postamble create mode 100644 locate/Makefile.preamble create mode 100644 locate/PB.project create mode 100644 locate/bigram/Makefile create mode 100644 locate/bigram/Makefile.postamble create mode 100644 locate/bigram/Makefile.preamble create mode 100644 locate/bigram/PB.project create mode 100644 locate/bigram/locate.bigram.c create mode 100644 locate/code/Makefile create mode 100644 locate/code/Makefile.postamble create mode 100644 locate/code/Makefile.preamble create mode 100644 locate/code/PB.project create mode 100644 locate/code/locate.code.c create mode 100644 locate/locate/Makefile create mode 100644 locate/locate/Makefile.postamble create mode 100644 locate/locate/Makefile.preamble create mode 100644 locate/locate/PB.project create mode 100644 locate/locate/locate.1 create mode 100644 locate/locate/locate.c create mode 100644 locate/locate/locate.h create mode 100644 locate/locate/pathnames.h create mode 100644 locate/locate/updatedb.csh create mode 100644 logname/Makefile create mode 100644 logname/Makefile.postamble create mode 100644 logname/Makefile.preamble create mode 100644 logname/PB.project create mode 100644 logname/logname.1 create mode 100644 logname/logname.c create mode 100644 nice/Makefile create mode 100644 nice/Makefile.postamble create mode 100644 nice/Makefile.preamble create mode 100644 nice/PB.project create mode 100644 nice/nice.1 create mode 100644 nice/nice.c create mode 100644 nohup/Makefile create mode 100644 nohup/Makefile.postamble create mode 100644 nohup/Makefile.preamble create mode 100644 nohup/PB.project create mode 100644 nohup/nohup.1 create mode 100644 nohup/nohup.c create mode 100644 printenv/Makefile create mode 100644 printenv/Makefile.postamble create mode 100644 printenv/Makefile.preamble create mode 100644 printenv/PB.project create mode 100644 printenv/printenv.1 create mode 100644 printenv/printenv.c create mode 100644 printf/Makefile create mode 100644 printf/Makefile.postamble create mode 100644 printf/Makefile.preamble create mode 100644 printf/PB.project create mode 100644 printf/printf.1 create mode 100644 printf/printf.c create mode 100644 pwd/Makefile create mode 100644 pwd/Makefile.postamble create mode 100644 pwd/Makefile.preamble create mode 100644 pwd/PB.project create mode 100644 pwd/pwd.1 create mode 100644 pwd/pwd.c create mode 100644 renice/Makefile create mode 100644 renice/Makefile.postamble create mode 100644 renice/Makefile.preamble create mode 100644 renice/PB.project create mode 100644 renice/renice.8 create mode 100644 renice/renice.c create mode 100644 script/Makefile create mode 100644 script/Makefile.postamble create mode 100644 script/Makefile.preamble create mode 100644 script/PB.project create mode 100644 script/script.1 create mode 100644 script/script.c create mode 100644 shlock/Makefile create mode 100644 shlock/Makefile.postamble create mode 100644 shlock/Makefile.preamble create mode 100644 shlock/PB.project create mode 100644 shlock/shlock.1 create mode 100644 shlock/shlock.c create mode 100644 sleep/Makefile create mode 100644 sleep/Makefile.postamble create mode 100644 sleep/Makefile.preamble create mode 100644 sleep/PB.project create mode 100644 sleep/sleep.1 create mode 100644 sleep/sleep.c create mode 100644 su/Makefile create mode 100644 su/Makefile.postamble create mode 100644 su/Makefile.preamble create mode 100644 su/PB.project create mode 100644 su/su.1 create mode 100644 su/su.c create mode 100644 tee/Makefile create mode 100644 tee/Makefile.postamble create mode 100644 tee/Makefile.preamble create mode 100644 tee/PB.project create mode 100644 tee/tee.1 create mode 100644 tee/tee.c create mode 100644 test/Makefile create mode 100644 test/Makefile.postamble create mode 100644 test/Makefile.preamble create mode 100644 test/PB.project create mode 100644 test/TEST.csh create mode 100644 test/[.1 create mode 100644 test/test.1 create mode 100644 test/test.c create mode 100644 time/Makefile create mode 100644 time/Makefile.postamble create mode 100644 time/Makefile.preamble create mode 100644 time/PB.project create mode 100644 time/time.1 create mode 100644 time/time.c create mode 100644 true/Makefile create mode 100644 true/Makefile.postamble create mode 100644 true/Makefile.preamble create mode 100644 true/PB.project create mode 100644 true/true.1 create mode 100644 true/true.c create mode 100644 uname/Makefile create mode 100644 uname/Makefile.postamble create mode 100644 uname/Makefile.preamble create mode 100644 uname/PB.project create mode 100644 uname/uname.1 create mode 100644 uname/uname.c create mode 100644 users/Makefile create mode 100644 users/Makefile.postamble create mode 100644 users/Makefile.preamble create mode 100644 users/PB.project create mode 100644 users/users.1 create mode 100644 users/users.c create mode 100644 w/Makefile create mode 100644 w/Makefile.postamble create mode 100644 w/Makefile.preamble create mode 100644 w/PB.project create mode 100644 w/extern.h create mode 100644 w/fmt.c create mode 100644 w/pr_time.c create mode 100644 w/proc_compare.c create mode 100644 w/uptime.1 create mode 100644 w/w.1 create mode 100644 w/w.c create mode 100644 whereis/Makefile create mode 100644 whereis/Makefile.postamble create mode 100644 whereis/Makefile.preamble create mode 100644 whereis/PB.project create mode 100644 whereis/whereis.1 create mode 100644 whereis/whereis.c create mode 100644 which/Makefile create mode 100644 which/Makefile.postamble create mode 100644 which/Makefile.preamble create mode 100644 which/PB.project create mode 100644 which/which.1 create mode 100644 which/which.csh create mode 100644 who/Makefile create mode 100644 who/Makefile.postamble create mode 100644 who/Makefile.preamble create mode 100644 who/PB.project create mode 100644 who/who.1 create mode 100644 who/who.c create mode 100644 window/Makefile create mode 100644 window/Makefile.postamble create mode 100644 window/Makefile.preamble create mode 100644 window/PB.project create mode 100644 window/README create mode 100644 window/alias.h create mode 100644 window/char.c create mode 100644 window/char.h create mode 100644 window/cmd.c create mode 100644 window/cmd1.c create mode 100644 window/cmd2.c create mode 100644 window/cmd3.c create mode 100644 window/cmd4.c create mode 100644 window/cmd5.c create mode 100644 window/cmd6.c create mode 100644 window/cmd7.c create mode 100644 window/compress.c create mode 100644 window/context.c create mode 100644 window/context.h create mode 100644 window/defs.h create mode 100644 window/error.c create mode 100644 window/lcmd.c create mode 100644 window/lcmd.h create mode 100644 window/lcmd1.c create mode 100644 window/lcmd2.c create mode 100644 window/local.h create mode 100644 window/main.c create mode 100644 window/mloop.c create mode 100644 window/parser.h create mode 100644 window/parser1.c create mode 100644 window/parser2.c create mode 100644 window/parser3.c create mode 100644 window/parser4.c create mode 100644 window/parser5.c create mode 100644 window/scanner.c create mode 100644 window/startup.c create mode 100644 window/string.c create mode 100644 window/token.h create mode 100644 window/tt.h create mode 100644 window/ttf100.c create mode 100644 window/ttgeneric.c create mode 100644 window/tth19.c create mode 100644 window/tth29.c create mode 100644 window/ttinit.c create mode 100644 window/ttoutput.c create mode 100644 window/tttermcap.c create mode 100644 window/tttvi925.c create mode 100644 window/ttwyse60.c create mode 100644 window/ttwyse75.c create mode 100644 window/ttzapple.c create mode 100644 window/ttzentec.c create mode 100644 window/value.h create mode 100644 window/var.c create mode 100644 window/var.h create mode 100644 window/win.c create mode 100644 window/window.1 create mode 100644 window/window_string.h create mode 100644 window/windowrc create mode 100644 window/ww.h create mode 100644 window/wwadd.c create mode 100644 window/wwalloc.c create mode 100644 window/wwbox.c create mode 100644 window/wwchild.c create mode 100644 window/wwclose.c create mode 100644 window/wwclreol.c create mode 100644 window/wwclreos.c create mode 100644 window/wwcursor.c create mode 100644 window/wwdata.c create mode 100644 window/wwdelchar.c create mode 100644 window/wwdelete.c create mode 100644 window/wwdelline.c create mode 100644 window/wwdump.c create mode 100644 window/wwend.c create mode 100644 window/wwenviron.c create mode 100644 window/wwerror.c create mode 100644 window/wwflush.c create mode 100644 window/wwframe.c create mode 100644 window/wwgets.c create mode 100644 window/wwinit.c create mode 100644 window/wwinschar.c create mode 100644 window/wwinsline.c create mode 100644 window/wwiomux.c create mode 100644 window/wwlabel.c create mode 100644 window/wwmisc.c create mode 100644 window/wwmove.c create mode 100644 window/wwopen.c create mode 100644 window/wwprintf.c create mode 100644 window/wwpty.c create mode 100644 window/wwputc.c create mode 100644 window/wwputs.c create mode 100644 window/wwredraw.c create mode 100644 window/wwredrawwin.c create mode 100644 window/wwrint.c create mode 100644 window/wwscroll.c create mode 100644 window/wwsize.c create mode 100644 window/wwspawn.c create mode 100644 window/wwsuspend.c create mode 100644 window/wwterminfo.c create mode 100644 window/wwtty.c create mode 100644 window/wwunframe.c create mode 100644 window/wwupdate.c create mode 100644 window/wwwrite.c create mode 100644 window/xx.c create mode 100644 window/xx.h create mode 100644 window/xxflush.c create mode 100644 xargs/Makefile create mode 100644 xargs/Makefile.postamble create mode 100644 xargs/Makefile.preamble create mode 100644 xargs/PB.project create mode 100644 xargs/pathnames.h create mode 100644 xargs/xargs.1 create mode 100644 xargs/xargs.c create mode 100644 yes/Makefile create mode 100644 yes/Makefile.postamble create mode 100644 yes/Makefile.preamble create mode 100644 yes/PB.project create mode 100644 yes/yes.1 create mode 100644 yes/yes.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0162509 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = shell_cmds + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Aggregate + +SUBPROJECTS = locate + +TOOLS = apply basename chroot date dirname echo env expr false\ + find getopt hostname id jot kill lastcomm logname nice\ + nohup printenv printf pwd renice script shlock sleep su\ + tee test time true uname users w whereis which who\ + window xargs yes + +OTHERSRCS = PROJECT Makefile.preamble Makefile Makefile.postamble + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = aggregate.make +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +NEXTSTEP_PB_CFLAGS = -Wall -Werror + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/Makefile.postamble b/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/Makefile.preamble b/Makefile.preamble new file mode 100644 index 0000000..8f8a3bd --- /dev/null +++ b/Makefile.preamble @@ -0,0 +1 @@ +include $(MAKEFILEPATH)/CoreOS/ProjectBuilder/Makefile.Preamble.Common diff --git a/PB.project b/PB.project new file mode 100644 index 0000000..66a0c64 --- /dev/null +++ b/PB.project @@ -0,0 +1,67 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + OTHER_SOURCES = (PROJECT, Makefile.preamble, Makefile, Makefile.postamble); + SUBPROJECTS = ( + apply, + basename, + chroot, + date, + dirname, + echo, + env, + expr, + false, + find, + getopt, + hostname, + id, + jot, + kill, + lastcomm, + locate, + logname, + nice, + nohup, + printenv, + printf, + pwd, + renice, + script, + shlock, + sleep, + su, + tee, + test, + time, + true, + uname, + users, + w, + whereis, + which, + who, + window, + xargs, + yes + ); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_COMPILEROPTIONS = "-Wall -Werror"; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = shell_cmds; + PROJECTTYPE = Aggregate; + PROJECTVERSION = 2.8; + TARGETS = (); + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/PROJECT b/PROJECT new file mode 100644 index 0000000..41782bc --- /dev/null +++ b/PROJECT @@ -0,0 +1,12 @@ +Project : shell_cmds +Description : Shell Commands +Distribution : NetBSD Fri Oct 9 20:13:59 PDT 1998 +Source : NetBSD Foundation, Inc. +Location : cvs.netbsd.org:/cvsroot +Owner : wsanchez +Releases : Titan +Dependancies : + +machine is disabled in favor of arch, which installs a link to itself as machine. + +w/fmt.c is copied from ps/fmt.c. We aren't doing the CVS trick of checking out that code from ps, because we don't use BSD ps; ps is a Mach client. diff --git a/apply/Makefile b/apply/Makefile new file mode 100644 index 0000000..6c0556b --- /dev/null +++ b/apply/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = apply + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = apply.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble apply.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/apply/Makefile.postamble b/apply/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/apply/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/apply/Makefile.preamble b/apply/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/apply/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/apply/PB.project b/apply/PB.project new file mode 100644 index 0000000..388e985 --- /dev/null +++ b/apply/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (apply.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, apply.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = apply; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/apply/apply.1 b/apply/apply.1 new file mode 100644 index 0000000..da353b1 --- /dev/null +++ b/apply/apply.1 @@ -0,0 +1,135 @@ +.\" $NetBSD: apply.1,v 1.7 1998/04/28 04:07:08 fair Exp $ +.\" +.\" Copyright (c) 1983, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)apply.1 8.2 (Berkeley) 4/4/94 +.\" +.Dd April 4, 1994 +.Dt APPLY 1 +.Os BSD 4.2 +.Sh NAME +.Nm apply +.Nd apply a command to a set of arguments +.Sh SYNOPSIS +.Nm +.Op Fl a Ns Ar c +.Op Fl Ns Ar # +.Ar command argument ... +.Sh DESCRIPTION +.Nm +runs the named +.Ar command +on each +argument +.Ar argument +in turn. +.Pp +Character sequences of the form +.Dq Li \&%d +in +.Ar command , +where +.Dq Li d +is a digit from 1 to 9, are replaced by the +.Li d Ns \'th +following unused +.Ar argument . +In this case, the largest digit number of arguments are discarded for +each execution of +.Ar command . +.Pp +The options are as follows: +.Bl -tag -width "-ac" +.It Fl Ns Ar # +Normally arguments are taken singly; the optional number +.Fl # +specifies the number of arguments to be passed to +.Ar command . +If the number is zero, +.Ar command +is run, without arguments, once for each +.Ar argument . +.Pp +If any sequences of +.Dq Li \&%d +occur in command, the +.Fl # +option is ignored. +.It Fl a Ns Ar c +The use of the character +.Dq Li % +as a magic character may be changed with the +.Fl a +option. +.El +.Sh ENVIRONMENT VARIABLES +The following environment variable affects the execution of +.Nm +: +.Bl -tag -width SHELL +.It Ev SHELL +Pathname of shell to use. +If this variable is not defined, the Bourne shell is used. +.El +.Sh EXAMPLES +.Bl -tag -width apply -compact +.It Li "apply echo a*" +is similar to +.Xr ls 1 ; +.It Li "apply \-2 cmp a1 b1 a2 b2 a3 b3" +compares the `a' files to the `b' files; +.It Li "apply \-0 who 1 2 3 4 5" +runs +.Xr who 1 +5 times; and +.It Li "apply \'ln %1 /usr/joe\'" * +links all files in the current directory to the directory +.Pa /usr/joe . +.El +.Sh Files +.Bl -tag -width /bin/sh -compact +.It Pa /bin/sh +Default shell +.El +.Sh AUTHOR +Rob Pike +.Sh BUGS +Shell metacharacters in +.Ar command +may have bizarre effects; it is best to enclose complicated +commands in single quotes +.Pq '' . +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.2 . diff --git a/apply/apply.c b/apply/apply.c new file mode 100644 index 0000000..80379a0 --- /dev/null +++ b/apply/apply.c @@ -0,0 +1,243 @@ +/* $NetBSD: apply.c,v 1.6 1997/12/31 05:53:45 thorpej Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Jan-Simon Pendry. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)apply.c 8.4 (Berkeley) 4/4/94"; +#else +__RCSID("$NetBSD: apply.c,v 1.6 1997/12/31 05:53:45 thorpej Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +int main __P((int, char **)); +void usage __P((void)); +int system __P((const char *)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int ch, clen, debug, i, l, magic, n, nargs, rval; + char *c, *cmd, *p, *q; + + debug = 0; + magic = '%'; /* Default magic char is `%'. */ + nargs = -1; + while ((ch = getopt(argc, argv, "a:d0123456789")) != -1) + switch (ch) { + case 'a': + if (optarg[1] != '\0') + errx(1, + "illegal magic character specification."); + magic = optarg[0]; + break; + case 'd': + debug = 1; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (nargs != -1) + errx(1, + "only one -# argument may be specified."); + nargs = optopt - '0'; + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc < 2) + usage(); + + /* + * The command to run is argv[0], and the args are argv[1..]. + * Look for %digit references in the command, remembering the + * largest one. + */ + for (n = 0, p = argv[0]; *p != '\0'; ++p) + if (p[0] == magic && isdigit(p[1]) && p[1] != '0') { + ++p; + if (p[0] - '0' > n) + n = p[0] - '0'; + } + + /* + * If there were any %digit references, then use those, otherwise + * build a new command string with sufficient %digit references at + * the end to consume (nargs) arguments each time round the loop. + * Allocate enough space to hold the maximum command. + */ + if ((cmd = malloc(sizeof("exec ") - 1 + + strlen(argv[0]) + 9 * (sizeof(" %1") - 1) + 1)) == NULL) + err(1, "malloc"); + + if (n == 0) { + /* If nargs not set, default to a single argument. */ + if (nargs == -1) + nargs = 1; + + p = cmd; + p += sprintf(cmd, "exec %s", argv[0]); + for (i = 1; i <= nargs; i++) + p += sprintf(p, " %c%d", magic, i); + + /* + * If nargs set to the special value 0, eat a single + * argument for each command execution. + */ + if (nargs == 0) + nargs = 1; + } else { + (void)sprintf(cmd, "exec %s", argv[0]); + nargs = n; + } + + /* + * Grab some space in which to build the command. Allocate + * as necessary later, but no reason to build it up slowly + * for the normal case. + */ + if ((c = malloc(clen = 1024)) == NULL) + err(1, "malloc"); + + /* + * (argc) and (argv) are still offset by one to make it simpler to + * expand %digit references. At the end of the loop check for (argc) + * equals 1 means that all the (argv) has been consumed. + */ + for (rval = 0; argc > nargs; argc -= nargs, argv += nargs) { + /* + * Find a max value for the command length, and ensure + * there's enough space to build it. + */ + for (l = strlen(cmd), i = 0; i < nargs; i++) + l += strlen(argv[i]); + if (l > clen && (c = realloc(c, clen = l)) == NULL) + err(1, "malloc"); + + /* Expand command argv references. */ + for (p = cmd, q = c; *p != '\0'; ++p) + if (p[0] == magic && isdigit(p[1]) && p[1] != '0') + q += sprintf(q, "%s", argv[(++p)[0] - '0']); + else + *q++ = *p; + + /* Terminate the command string. */ + *q = '\0'; + + /* Run the command. */ + if (debug) + (void)printf("%s\n", c); + else + if (system(c)) + rval = 1; + } + + if (argc != 1) + errx(1, "expecting additional argument%s after \"%s\"", + (nargs - argc) ? "s" : "", argv[argc - 1]); + exit(rval); +} + +/* + * system -- + * Private version of system(3). Use the user's SHELL environment + * variable as the shell to execute. + */ +int +system(command) + const char *command; +{ + static char *name, *shell; + union wait pstat; + pid_t pid; + int omask; + sig_t intsave, quitsave; + + if (shell == NULL) { + if ((shell = getenv("SHELL")) == NULL) + shell = _PATH_BSHELL; + if ((name = strrchr(shell, '/')) == NULL) + name = shell; + else + ++name; + } + if (!command) /* just checking... */ + return(1); + + omask = sigblock(sigmask(SIGCHLD)); + switch(pid = vfork()) { + case -1: /* error */ + err(1, "vfork"); + case 0: /* child */ + (void)sigsetmask(omask); + execl(shell, name, "-c", command, NULL); + warn("%s", shell); + _exit(1); + } + intsave = signal(SIGINT, SIG_IGN); + quitsave = signal(SIGQUIT, SIG_IGN); + pid = waitpid(pid, (int *)&pstat, 0); + (void)sigsetmask(omask); + (void)signal(SIGINT, intsave); + (void)signal(SIGQUIT, quitsave); + return(pid == -1 ? -1 : pstat.w_status); +} + +void +usage() +{ + + (void)fprintf(stderr, + "usage: apply [-a magic] [-0123456789] command arguments ...\n"); + exit(1); +} diff --git a/basename/Makefile b/basename/Makefile new file mode 100644 index 0000000..48902e6 --- /dev/null +++ b/basename/Makefile @@ -0,0 +1,49 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = basename + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = basename.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble basename.1\ + dirname.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/basename/Makefile.postamble b/basename/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/basename/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/basename/Makefile.preamble b/basename/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/basename/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/basename/PB.project b/basename/PB.project new file mode 100644 index 0000000..041f770 --- /dev/null +++ b/basename/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (basename.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, basename.1, dirname.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = basename; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/basename/basename.1 b/basename/basename.1 new file mode 100644 index 0000000..d2cf5b7 --- /dev/null +++ b/basename/basename.1 @@ -0,0 +1,94 @@ +.\" $NetBSD: basename.1,v 1.11 1997/11/15 20:16:16 msaitoh Exp $ +.\" +.\" Copyright (c) 1990, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)basename.1 8.2 (Berkeley) 4/18/94 +.\" +.Dd April 18, 1994 +.Dt BASENAME 1 +.Os +.Sh NAME +.Nm basename , +.Nm dirname +.Nd return filename or directory portion of pathname +.Sh SYNOPSIS +.Nm +.Ar string +.Op Ar suffix +.Nm dirname +.Ar string +.Sh DESCRIPTION +.Nm +deletes any prefix ending with the last slash +.Ql \&/ +character present in +.Ar string , +and a +.Ar suffix , +if given. +The resulting filename is written to the standard output. +A non-existent suffix is ignored. +.Pp +.Nm dirname +deletes the filename portion, beginning +with the last slash +.Ql \&/ +character to the end of +.Ar string , +and writes the result to the standard output. +.Sh EXAMPLES +The following line sets the shell variable +.Ev FOO +to +.Pa /usr/bin . +.Pp +.Dl FOO=`dirname /usr/bin/trail` +.Sh DIAGNOSTICS +Both the +.Nm +and +.Nm dirname +utilities +exit 0 on success, and >0 if an error occurs. +.Sh SEE ALSO +.Xr csh 1 , +.Xr sh 1 +.Sh STANDARDS +The +.Nm +and +.Nm dirname +utilities conform to +.St -p1003.2-92 . diff --git a/basename/basename.c b/basename/basename.c new file mode 100644 index 0000000..ac02aa1 --- /dev/null +++ b/basename/basename.c @@ -0,0 +1,148 @@ +/* $NetBSD: basename.c,v 1.10 1997/10/18 12:18:20 lukem Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)basename.c 8.4 (Berkeley) 5/4/95"; +#endif +__RCSID("$NetBSD: basename.c,v 1.10 1997/10/18 12:18:20 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include + +int main __P((int, char **)); +void usage __P((void)); + +int +main(argc, argv) + int argc; + char **argv; +{ + char *p; + int ch; + + setlocale(LC_ALL, ""); + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 1 && argc != 2) + usage(); + + /* + * (1) If string is // it is implementation defined whether steps (2) + * through (5) are skipped or processed. + * + * (2) If string consists entirely of slash characters, string shall + * be set to a single slash character. In this case, skip steps + * (3) through (5). + */ + for (p = *argv;; ++p) { + if (!*p) { + if (p > *argv) + (void)printf("/\n"); + else + (void)printf("\n"); + exit(0); + } + if (*p != '/') + break; + } + + /* + * (3) If there are any trailing slash characters in string, they + * shall be removed. + */ + for (; *p; ++p) + continue; + while (*--p == '/') + continue; + *++p = '\0'; + + /* + * (4) If there are any slash characters remaining in string, the + * prefix of string up to an including the last slash character + * in string shall be removed. + */ + while (--p >= *argv) + if (*p == '/') + break; + ++p; + + /* + * (5) If the suffix operand is present, is not identical to the + * characters remaining in string, and is identical to a suffix + * of the characters remaining in string, the suffix suffix + * shall be removed from string. + */ + if (*++argv) { + int suffixlen, stringlen, off; + + suffixlen = strlen(*argv); + stringlen = strlen(p); + + if (suffixlen < stringlen) { + off = stringlen - suffixlen; + if (!strcmp(p + off, *argv)) + p[off] = '\0'; + } + } + (void)printf("%s\n", p); + exit(0); +} + +void +usage() +{ + + (void)fprintf(stderr, "usage: basename string [suffix]\n"); + exit(1); +} diff --git a/basename/dirname.1 b/basename/dirname.1 new file mode 100644 index 0000000..ee3bc6f --- /dev/null +++ b/basename/dirname.1 @@ -0,0 +1 @@ +.so man1/basename.1 diff --git a/chroot/Makefile b/chroot/Makefile new file mode 100644 index 0000000..7d2e40b --- /dev/null +++ b/chroot/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = chroot + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = chroot.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble chroot.8 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/sbin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/chroot/Makefile.postamble b/chroot/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/chroot/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/chroot/Makefile.preamble b/chroot/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/chroot/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/chroot/PB.project b/chroot/PB.project new file mode 100644 index 0000000..f706b95 --- /dev/null +++ b/chroot/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (chroot.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, chroot.8); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/sbin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = chroot; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/chroot/chroot.8 b/chroot/chroot.8 new file mode 100644 index 0000000..9375bfd --- /dev/null +++ b/chroot/chroot.8 @@ -0,0 +1,102 @@ +.\" Copyright (c) 1988, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)chroot.8 8.1 (Berkeley) 6/9/93 +.\" $NetBSD: chroot.8,v 1.7 1998/10/06 03:47:50 mrg Exp $ +.\" +.Dd October 6, 1998 +.Dt CHROOT 8 +.Os BSD 4.3 +.Sh NAME +.Nm chroot +.Nd change root directory +.Sh SYNOPSIS +.Nm +.Op Fl u user +.Op Fl g group +.Op Fl G group,group,... +.Ar newroot +.Op Ar command +.Sh DESCRIPTION +The +.Nm +command changes its root directory to the supplied directory +.Ar newroot +and exec's +.Ar command , +if supplied, or an interactive copy of your shell. +.Pp +If the +.Fl u , +.Fl g +or +.Fl G +options are given, the user, group and group list of the process are +set to these values after the chroot has taken place. See +.Xr setgid 2 , +.Xr setgroups 2 , +.Xr setuid 2 , +.Xr getgrnam 3 +and +.Xr getpwnam 3 . +.Pp +Note, +.Ar command +or the shell are run as your real-user-id. +.Sh ENVIRONMENT +The following environment variable is referenced by +.Nm "" : +.Bl -tag -width SHELL +.It Ev SHELL +If set, +the string specified by +.Ev SHELL +is interpreted as the name of +the shell to exec. +If the variable +.Ev SHELL +is not set, +.Pa /bin/sh +is used. +.El +.Sh SEE ALSO +.Xr chdir 2 , +.Xr chroot 2 , +.Xr environ 7 +.Sh HISTORY +The +.Nm +utility first appeared in +.Bx 4.4 . +.Sh SECURITY CONSIDERATIONS +.Nm +should never be installed setuid root, as it would then be possible +to exploit the program to gain root privileges. diff --git a/chroot/chroot.c b/chroot/chroot.c new file mode 100644 index 0000000..c9c38f5 --- /dev/null +++ b/chroot/chroot.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)chroot.c 8.1 (Berkeley) 6/9/93"; +#else +__RCSID("$NetBSD: chroot.c,v 1.7 1998/10/06 03:47:51 mrg Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main __P((int, char **)); +void usage __P((void)) __attribute__((__noreturn__)); + +char *user; /* user to switch to before running program */ +char *group; /* group to switch to ... */ +char *grouplist; /* group list to switch to ... */ + +int +main(argc, argv) + int argc; + char *argv[]; +{ + struct group *gp; + struct passwd *pw; + char *shell, *endp, *comma; + gid_t gid = 0, gidlist[NGROUPS_MAX]; + uid_t uid = 0; + int ch, gids; + + while ((ch = getopt(argc, argv, "G:g:u:")) != -1) + switch(ch) { + case 'u': + user = optarg; + break; + case 'g': + group = optarg; + break; + case 'G': + grouplist = optarg; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc < 1) + usage(); + + if (group) { + if (isdigit(*group)) { + gid = (gid_t)strtol(group, &endp, 0); + if (endp == group) + goto getgroup; + } else { +getgroup: + if ((gp = getgrnam(group))) + gid = gp->gr_gid; + else + errx(1, "no such group %s", group); + } + } + + for (gids = 0; grouplist; ) { + comma = strchr(grouplist, ','); + + if (comma) + *comma++ = '\0'; + + if (isdigit(*grouplist)) { + gidlist[gids] = (gid_t)strtol(grouplist, &endp, 0); + if (endp == grouplist) + goto getglist; + } else { +getglist: + if ((gp = getgrnam(grouplist))) + gidlist[gids] = gp->gr_gid; + else + errx(1, "no such group %s", group); + } + gids++; + grouplist = comma; + } + + if (user) { + if (isdigit(*user)) { + uid = (uid_t)strtol(user, &endp, 0); + if (endp == user) + goto getuser; + } else { +getuser: + if ((pw = getpwnam(user))) + uid = pw->pw_uid; + else + errx(1, "no such user %s", user); + } + } + + if (chdir(argv[0]) || chroot(".")) + err(1, "%s", argv[0]); + + if (gids && setgroups(gids, gidlist) < 0) + err(1, "setgroups"); + if (group && setgid(gid) < 0) + err(1, "setgid"); + if (user && setuid(uid) < 0) + err(1, "setuid"); + + if (argv[1]) { + execvp(argv[1], &argv[1]); + err(1, "%s", argv[1]); + } + + if (!(shell = getenv("SHELL"))) + shell = _PATH_BSHELL; + execlp(shell, shell, "-i", NULL); + err(1, "%s", shell); + /* NOTREACHED */ +} + +void +usage() +{ + (void)fprintf(stderr, "usage: chroot [-g group] [-G group,group,...] " + "[-u user] newroot [command]\n"); + exit(1); +} diff --git a/date/Makefile b/date/Makefile new file mode 100644 index 0000000..d96b895 --- /dev/null +++ b/date/Makefile @@ -0,0 +1,50 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = date + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = extern.h + +CFILES = date.c netdate.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble date.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/date/Makefile.postamble b/date/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/date/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/date/Makefile.preamble b/date/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/date/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/date/PB.project b/date/PB.project new file mode 100644 index 0000000..dc8850c --- /dev/null +++ b/date/PB.project @@ -0,0 +1,28 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + HEADERSEARCH = (); + H_FILES = (extern.h); + OTHER_LINKED = (date.c, netdate.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, date.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = date; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/date/date.1 b/date/date.1 new file mode 100644 index 0000000..4fe9b53 --- /dev/null +++ b/date/date.1 @@ -0,0 +1,213 @@ +.\" $NetBSD: date.1,v 1.22 1998/06/08 09:07:13 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)date.1 8.3 (Berkeley) 4/28/95 +.\" +.Dd January 20, 1998 +.Dt DATE 1 +.Os +.Sh NAME +.Nm date +.Nd display or set date and time +.Sh SYNOPSIS +.Nm +.Op Fl nu +.Op Fl r Ar seconds +.Op Cm + Ns Ar format +.Nm "" +.Ar [[[[[cc]yy]mm]dd]hh]mm[\&.ss] +.Sh DESCRIPTION +.Nm +displays the current date and time when invoked without arguments. +Providing arguments will format the date and time in a user-defined +way or set the date. +Only the superuser may set the date. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl n +The utility +.Xr timed 8 +is used to synchronize the clocks on groups of machines. +By default, if +timed +is running, +.Nm +will set the time on all of the machines in the local group. +The +.Fl n +option stops +.Nm +from setting the time for other than the current machine. +.It Fl r +Print out the date and time that is +.Ar seconds +from the Epoch. +.It Fl u +Display or set the date in +.Tn UTC +(universal) time. +.El +.Pp +An operand with a leading plus (``+'') sign signals a user-defined format +string which specifies the format in which to display the date and time. +The format string may contain any of the conversion specifications described +in the +.Xr strftime 3 +manual page, as well as any arbitrary text. +A character is always output after the characters specified by +the format string. +The format string for the default display is: +.Bd -literal -offset indent +``%a %b %e %H:%M:%S %Z %Y''. +.Ed +.Pp +If an operand does not have a leading plus sign, it is interpreted as +a value for setting the system's notion of the current date and time. +The canonical representation for setting the date and time is: +.Pp +.Bl -tag -width Ds -compact -offset indent +.It Ar cc +The first two digits of the year (the century). +.It Ar yy +The second two digits of the year. If +.Dq yy +is specified, but +.Dq cc +is not, a value for +.Dq yy +between 69 and 99 results in a +.Dq cc +value of 19. Otherwise, a +.Dq cc +value of 20 is used. +.It Ar mm +The month of the year, from 1 to 12. +.It Ar dd +The day of the month, from 1 to 31. +.It Ar hh +The hour of the day, from 0 to 23. +.It Ar mm +The minute of the hour, from 0 to 59. +.It Ar ss +The second of the minute, from 0 to 61. +.El +.Pp +Everything but the minutes is optional. +.Pp +Time changes for Daylight Saving and Standard time and leap seconds +and years are handled automatically. +.Sh EXAMPLES +The command: +.Bd -literal -offset indent +date ``+DATE: %m/%d/%y%nTIME: %H:%M:%S'' +.Ed +.Pp +will display: +.Bd -literal -offset indent +DATE: 11/21/87 +TIME: 13:36:16 +.Ed +.Pp +The command: +.Bd -literal -offset indent +date 8506131627 +.Ed +.Pp +sets the date to +.Dq Li "June 13, 1985, 4:27 PM" . +.Pp +The command: +.Bd -literal -offset indent +date 1432 +.Ed +.Pp +sets the time to +.Li "2:32 PM" , +without modifying the date. +.Sh ENVIRONMENT VARIABLES +The following environment variables affect the execution of +.Nm +: +.Bl -tag -width TZ +.It Ev TZ +The timezone to use when displaying dates. +See +.Xr environ 7 +for more information. +.El +.Sh FILES +.Bl -tag -width /var/log/messages -compact +.It Pa /var/log/wtmp +A record of date resets and time changes. +.It Pa /var/log/messages +A record of the user setting the time. +.El +.Sh SEE ALSO +.Xr gettimeofday 2 , +.Xr strftime 3 , +.Xr utmp 5 , +.Xr timed 8 +.Rs +.%T "TSP: The Time Synchronization Protocol for UNIX 4.3BSD" +.%A R. Gusella +.%A S. Zatti +.Re +.Sh DIAGNOSTICS +Exit status is 0 on success, 1 if unable to set the date, and 2 +if able to set the local date, but unable to set it globally. +.Pp +Occasionally, when +.Xr timed 8 +synchronizes the time on many hosts, the setting of a new time value may +require more than a few seconds. +On these occasions, +.Nm +prints: +.Ql Network time being set . +The message +.Ql Communication error with timed +occurs when the communication +between +.Nm +and +timed +fails. +.Sh STANDARDS +The +.Nm +utility is expected to be compatible with +.St -p1003.2 . diff --git a/date/date.c b/date/date.c new file mode 100644 index 0000000..9c59b07 --- /dev/null +++ b/date/date.c @@ -0,0 +1,244 @@ +/* $NetBSD: date.c,v 1.25 1998/07/28 11:41:47 mycroft Exp $ */ + +/* + * Copyright (c) 1985, 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( +"@(#) Copyright (c) 1985, 1987, 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: date.c,v 1.25 1998/07/28 11:41:47 mycroft Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "extern.h" + +time_t tval; +int retval, nflag; + +int main __P((int, char *[])); +static void setthetime __P((const char *)); +static void badformat __P((void)); +static void badtime __P((void)); +static void usage __P((void)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + extern int optind; + extern char *optarg; + int ch, rflag; + char *format, buf[1024]; + + (void)setlocale(LC_ALL, ""); + + rflag = 0; + while ((ch = getopt(argc, argv, "nr:u")) != -1) + switch((char)ch) { + case 'n': /* don't set network */ + nflag = 1; + break; + case 'r': /* user specified seconds */ + rflag = 1; + tval = atol(optarg); + break; + case 'u': /* do everything in GMT */ + (void)setenv("TZ", "GMT0", 1); + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + if (!rflag && time(&tval) == -1) + err(1, "time"); + + format = "%a %b %e %H:%M:%S %Z %Y"; + + /* allow the operands in any order */ + if (*argv && **argv == '+') { + format = *argv + 1; + ++argv; + } + + if (*argv) { + setthetime(*argv); + ++argv; + } + + if (*argv && **argv == '+') + format = *argv + 1; + + (void)strftime(buf, sizeof(buf), format, localtime(&tval)); + (void)printf("%s\n", buf); + exit(retval); + /* NOTREACHED */ +} + +#define ATOI2(s) ((s) += 2, ((s)[-2] - '0') * 10 + ((s)[-1] - '0')) + +void +setthetime(p) + const char *p; +{ + struct tm *lt; + struct timeval tv; + const char *dot, *t; + int yearset, len; + + for (t = p, dot = NULL; *t; ++t) { + if (isdigit(*t)) + continue; + if (*t == '.' && dot == NULL) { + dot = t; + continue; + } + badformat(); + } + + lt = localtime(&tval); + + if (dot != NULL) { /* .ss */ + len = strlen(dot); + if (len != 3) + badformat(); + ++dot; + lt->tm_sec = ATOI2(dot); + } else { + len = 0; + lt->tm_sec = 0; + } + + yearset = 0; + switch (strlen(p) - len) { + case 12: /* cc */ + lt->tm_year = ATOI2(p) * 100 - TM_YEAR_BASE; + yearset = 1; + /* FALLTHROUGH */ + case 10: /* yy */ + if (yearset) { + lt->tm_year += ATOI2(p); + } else { + yearset = ATOI2(p); + if (yearset < 69) + lt->tm_year = yearset + 2000 - TM_YEAR_BASE; + else + lt->tm_year = yearset + 1900 - TM_YEAR_BASE; + } + /* FALLTHROUGH */ + case 8: /* mm */ + lt->tm_mon = ATOI2(p); + --lt->tm_mon; /* time struct is 0 - 11 */ + /* FALLTHROUGH */ + case 6: /* dd */ + lt->tm_mday = ATOI2(p); + /* FALLTHROUGH */ + case 4: /* hh */ + lt->tm_hour = ATOI2(p); + /* FALLTHROUGH */ + case 2: /* mm */ + lt->tm_min = ATOI2(p); + break; + default: + badformat(); + } + + /* convert broken-down time to GMT clock time */ + if ((tval = mktime(lt)) == -1) + badtime(); + + /* set the time */ + if (nflag || netsettime(tval)) { + logwtmp("|", "date", ""); + tv.tv_sec = tval; + tv.tv_usec = 0; + if (settimeofday(&tv, NULL)) { + perror("date: settimeofday"); + exit(1); + } + logwtmp("{", "date", ""); + } + + if ((p = getlogin()) == NULL) + p = "???"; + syslog(LOG_AUTH | LOG_NOTICE, "date set by %s", p); +} + +static void +badformat() +{ + warnx("illegal time format"); + usage(); +} + +static void +badtime() +{ + errx(1, "illegal time"); +} + +static void +usage() +{ + (void)fprintf(stderr, + "usage: date [-nu] [-r seconds] [+format]\n"); + (void)fprintf(stderr, " date [[[[[cc]yy]mm]dd]hh]mm[.ss]\n"); + exit(1); + /* NOTREACHED */ +} diff --git a/date/extern.h b/date/extern.h new file mode 100644 index 0000000..c0d7fbe --- /dev/null +++ b/date/extern.h @@ -0,0 +1,38 @@ +/* $NetBSD: extern.h,v 1.3 1995/03/21 09:03:52 cgd Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)extern.h 8.1 (Berkeley) 5/31/93 + */ + +int netsettime __P((time_t)); diff --git a/date/netdate.c b/date/netdate.c new file mode 100644 index 0000000..ee7b8ff --- /dev/null +++ b/date/netdate.c @@ -0,0 +1,195 @@ +/* $NetBSD: netdate.c,v 1.16 1998/07/28 03:47:15 mycroft Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)netdate.c 8.2 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: netdate.c,v 1.16 1998/07/28 03:47:15 mycroft Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include + +#include +#include +#define TSPTYPES +#include + +#include +#include +#include +#include +#include + +#include "extern.h" + +#define WAITACK 2 /* seconds */ +#define WAITDATEACK 5 /* seconds */ + +extern int retval; + +/* + * Set the date in the machines controlled by timedaemons by communicating the + * new date to the local timedaemon. If the timedaemon is in the master state, + * it performs the correction on all slaves. If it is in the slave state, it + * notifies the master that a correction is needed. + * Returns 0 on success. Returns > 0 on failure, setting retval to 2; + */ +int +netsettime(tval) + time_t tval; +{ + struct timeval tout; + struct servent *sp; + struct tsp msg; + struct sockaddr_in sin, dest, from; + fd_set ready; + long waittime; + int s, length, timed_ack, found, error; +#ifdef IP_PORTRANGE + int on; +#endif + char hostname[MAXHOSTNAMELEN + 1]; + + if ((sp = getservbyname("timed", "udp")) == NULL) { + warnx("udp/timed: unknown service"); + return (retval = 2); + } + + (void)memset(&dest, 0, sizeof(dest)); + dest.sin_len = sizeof(struct sockaddr_in); + dest.sin_family = AF_INET; + dest.sin_port = sp->s_port; + dest.sin_addr.s_addr = htonl(INADDR_ANY); + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + if (errno != EPROTONOSUPPORT) + warn("timed"); + return (retval = 2); + } + +#ifdef IP_PORTRANGE + on = IP_PORTRANGE_LOW; + if (setsockopt(s, IPPROTO_IP, IP_PORTRANGE, &on, sizeof(on)) < 0) { + warn("setsockopt"); + goto bad; + } +#endif + + (void)memset(&sin, 0, sizeof(sin)); + sin.sin_len = sizeof(struct sockaddr_in); + sin.sin_family = AF_INET; + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + warn("bind"); + goto bad; + } + + msg.tsp_type = TSP_SETDATE; + msg.tsp_vers = TSPVERSION; + if (gethostname(hostname, sizeof(hostname))) { + warn("gethostname"); + goto bad; + } + hostname[sizeof(hostname) - 1] = '\0'; + (void)strncpy(msg.tsp_name, hostname, sizeof(hostname)); + msg.tsp_seq = htons((u_short)0); + msg.tsp_time.tv_sec = htonl((u_long)tval); + msg.tsp_time.tv_usec = htonl((u_long)0); + length = sizeof(struct sockaddr_in); + if (connect(s, (struct sockaddr *)&dest, length) < 0) { + warn("connect"); + goto bad; + } + if (send(s, (char *)&msg, sizeof(struct tsp), 0) < 0) { + if (errno != ECONNREFUSED) + warn("send"); + goto bad; + } + + timed_ack = -1; + waittime = WAITACK; +loop: + tout.tv_sec = waittime; + tout.tv_usec = 0; + + FD_ZERO(&ready); + FD_SET(s, &ready); + found = select(FD_SETSIZE, &ready, (fd_set *)0, (fd_set *)0, &tout); + + length = sizeof(error); + if (!getsockopt(s, + SOL_SOCKET, SO_ERROR, (char *)&error, &length) && error) { + if (error != ECONNREFUSED) + warn("send (delayed error)"); + goto bad; + } + + if (found > 0 && FD_ISSET(s, &ready)) { + length = sizeof(struct sockaddr_in); + if (recvfrom(s, &msg, sizeof(struct tsp), 0, + (struct sockaddr *)&from, &length) < 0) { + if (errno != ECONNREFUSED) + warn("recvfrom"); + goto bad; + } + msg.tsp_seq = ntohs(msg.tsp_seq); + msg.tsp_time.tv_sec = ntohl(msg.tsp_time.tv_sec); + msg.tsp_time.tv_usec = ntohl(msg.tsp_time.tv_usec); + switch (msg.tsp_type) { + case TSP_ACK: + timed_ack = TSP_ACK; + waittime = WAITDATEACK; + goto loop; + case TSP_DATEACK: + (void)close(s); + return (0); + default: + warnx("wrong ack received from timed: %s", + tsptype[msg.tsp_type]); + timed_ack = -1; + break; + } + } + if (timed_ack == -1) + warnx("can't reach time daemon, time set locally"); + +bad: + (void)close(s); + return (retval = 2); +} diff --git a/dirname/Makefile b/dirname/Makefile new file mode 100644 index 0000000..331901c --- /dev/null +++ b/dirname/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = dirname + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = dirname.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/dirname/Makefile.postamble b/dirname/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/dirname/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/dirname/Makefile.preamble b/dirname/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/dirname/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/dirname/PB.project b/dirname/PB.project new file mode 100644 index 0000000..d6e16ab --- /dev/null +++ b/dirname/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (dirname.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = dirname; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/dirname/dirname.c b/dirname/dirname.c new file mode 100644 index 0000000..19f5b37 --- /dev/null +++ b/dirname/dirname.c @@ -0,0 +1,155 @@ +/* $NetBSD: dirname.c,v 1.7 1997/10/18 13:21:41 lukem Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; +#endif +__RCSID("$NetBSD: dirname.c,v 1.7 1997/10/18 13:21:41 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include + +int main __P((int, char **)); +static void usage __P((void)); + +int +main(argc, argv) + int argc; + char **argv; +{ + register char *p; + int ch; + + setlocale(LC_ALL, ""); + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 1) + usage(); + + /* + * (1) If string is //, skip steps (2) through (5). + * (2) If string consists entirely of slash characters, string + * shall be set to a single slash character. In this case, + * skip steps (3) through (8). + */ + for (p = *argv;; ++p) { + if (!*p) { + if (p > *argv) + (void)printf("/\n"); + else + (void)printf(".\n"); + exit(0); + } + if (*p != '/') + break; + } + + /* + * (3) If there are any trailing slash characters in string, they + * shall be removed. + */ + for (; *p; ++p); + while (*--p == '/') + continue; + *++p = '\0'; + + /* + * (4) If there are no slash characters remaining in string, + * string shall be set to a single period character. In this + * case skip steps (5) through (8). + * + * (5) If there are any trailing nonslash characters in string, + * they shall be removed. + */ + while (--p >= *argv) + if (*p == '/') + break; + ++p; + if (p == *argv) { + (void)printf(".\n"); + exit(0); + } + + /* + * (6) If the remaining string is //, it is implementation defined + * whether steps (7) and (8) are skipped or processed. + * + * This case has already been handled, as part of steps (1) and (2). + */ + + /* + * (7) If there are any trailing slash characters in string, they + * shall be removed. + */ + while (--p >= *argv) + if (*p != '/') + break; + ++p; + + /* + * (8) If the remaining string is empty, string shall be set to + * a single slash character. + */ + *p = '\0'; + (void)printf("%s\n", p == *argv ? "/" : *argv); + exit(0); +} + +static void +usage() +{ + + (void)fprintf(stderr, "usage: dirname path\n"); + exit(1); +} + diff --git a/echo/Makefile b/echo/Makefile new file mode 100644 index 0000000..f2346d3 --- /dev/null +++ b/echo/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = echo + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = echo.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble echo.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/echo/Makefile.postamble b/echo/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/echo/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/echo/Makefile.preamble b/echo/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/echo/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/echo/PB.project b/echo/PB.project new file mode 100644 index 0000000..e7ed565 --- /dev/null +++ b/echo/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (echo.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, echo.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = echo; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/echo/echo.1 b/echo/echo.1 new file mode 100644 index 0000000..e04e4cd --- /dev/null +++ b/echo/echo.1 @@ -0,0 +1,72 @@ +.\" $NetBSD: echo.1,v 1.8 1997/10/20 08:51:49 enami Exp $ +.\" +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)echo.1 8.1 (Berkeley) 7/22/93 +.\" +.Dd July 22, 1993 +.Dt ECHO 1 +.Os +.Sh NAME +.Nm echo +.Nd write arguments to the standard output +.Sh SYNOPSIS +.Nm +.Op Fl n +.Op "string ..." +.Sh DESCRIPTION +The +.Nm +utility writes any specified operands, separated by single blank (`` '') +characters and followed by a newline (``\en'') character, to the standard +output. +.Pp +The following option is available: +.Bl -tag -width flag +.It Fl n +Do not print the trailing newline character. +.El +.Pp +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Sh SEE ALSO +.Xr printf 1 +.Sh STANDARDS +The +.Nm +utility is expected to be +.St -p1003.2 +compatible. diff --git a/echo/echo.c b/echo/echo.c new file mode 100644 index 0000000..e427f46 --- /dev/null +++ b/echo/echo.c @@ -0,0 +1,82 @@ +/* $NetBSD: echo.c,v 1.8 1997/11/05 21:19:56 cgd Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( +"@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93"; +#else +__RCSID("$NetBSD: echo.c,v 1.8 1997/11/05 21:19:56 cgd Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include + +int main __P((int, char *[])); + +/* ARGSUSED */ +int +main(argc, argv) + int argc; + char *argv[]; +{ + int nflag; + + /* This utility may NOT do getopt(3) option parsing. */ + if (*++argv && !strcmp(*argv, "-n")) { + ++argv; + nflag = 1; + } + else + nflag = 0; + + while (*argv) { + (void)printf("%s", *argv); + if (*++argv) + (void)putchar(' '); + } + if (!nflag) + (void)putchar('\n'); + exit(0); + /* NOTREACHED */ +} diff --git a/env/Makefile b/env/Makefile new file mode 100644 index 0000000..f1aea83 --- /dev/null +++ b/env/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = env + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = env.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble env.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/env/Makefile.postamble b/env/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/env/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/env/Makefile.preamble b/env/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/env/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/env/PB.project b/env/PB.project new file mode 100644 index 0000000..8cfa454 --- /dev/null +++ b/env/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (env.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, env.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = env; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/env/env.1 b/env/env.1 new file mode 100644 index 0000000..d281dc9 --- /dev/null +++ b/env/env.1 @@ -0,0 +1,125 @@ +.\" $NetBSD: env.1,v 1.6 1997/10/18 13:55:22 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1990 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91 +.\" $NetBSD: env.1,v 1.6 1997/10/18 13:55:22 lukem Exp $ +.\" +.Dd August 27, 1993 +.Dt ENV 1 +.Os +.Sh NAME +.Nm env +.Nd set and print environment +.Sh SYNOPSIS +.Nm +.Op Fl i +.Op Ar name=value ... +.Oo +.Ar utility +.Op argument ... +.Oc +.Sh DESCRIPTION +.Nm +executes +.Ar utility +after modifying the environment as +specified on the command line. The option +.Ar name=value +specifies +an environmental variable, +.Ar name , +with a value of +.Ar value . +The option +.Sq Fl i +causes +.Nm +to completely ignore the environment +it inherits. +.Pp +If no +.Ar utility +is specified, +.Nm +prints out the names and values +of the variables in the environment, with one +.Ar name=value +pair per line. +.Sh DIAGNOSTICS +If the +.Ar utility +is invoked, the exit status of +.Nm +shall be the exit status of +.Ar utility; +otherwise, the +.Nm +utility exits with one of the following values: +.Bl -tag -width Ds +.It 0 +The +.Nm +utility completed successfully +.It 1-125 +An error occurred in the +.Nm +utility. +.It 126 +The utility specified by +.Ar utility +was found, but could not be invoked. +.It 127 +The utility specified by +.Ar utility +could not be found. +.El +.Sh COMPATIBILITY +The historic +.Fl +option has been deprecated but is still supported in this implementation. +.Sh SEE ALSO +.Xr execvp 3 , +.Xr environ 7 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . +.Sh BUGS +.Nm +doesn't handle commands with equal +.Pq Dq = +signs in their +names, for obvious reasons. diff --git a/env/env.c b/env/env.c new file mode 100644 index 0000000..42b7542 --- /dev/null +++ b/env/env.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +/*static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94";*/ +__RCSID("$NetBSD: env.c,v 1.10 1997/10/18 13:55:28 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include + +int main __P((int, char **)); +static void usage __P((void)); + +int +main(argc, argv) + int argc; + char **argv; +{ + extern char **environ; + extern int optind; + char **ep, *p; + char *cleanenv[1]; + int ch; + + setlocale(LC_ALL, ""); + + while ((ch = getopt(argc, argv, "-i")) != -1) + switch((char)ch) { + case '-': /* obsolete */ + case 'i': + environ = cleanenv; + cleanenv[0] = NULL; + break; + case '?': + default: + usage(); + } + + for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) + (void)setenv(*argv, ++p, 1); + + if (*argv) { + /* return 127 if the command to be run could not be found; 126 + if the command was was found but could not be invoked */ + + execvp(*argv, argv); + err((errno == ENOENT) ? 127 : 126, "%s", *argv); + /* NOTREACHED */ + } + + for (ep = environ; *ep; ep++) + (void)printf("%s\n", *ep); + + exit(0); +} + +static void +usage () +{ + (void) fprintf(stderr, "usage: env [-i] [name=value ...] [command]\n"); + exit (1); +} diff --git a/expr/Makefile b/expr/Makefile new file mode 100644 index 0000000..8df16b0 --- /dev/null +++ b/expr/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = expr + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = expr.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble expr.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/expr/Makefile.postamble b/expr/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/expr/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/expr/Makefile.preamble b/expr/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/expr/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/expr/PB.project b/expr/PB.project new file mode 100644 index 0000000..4a9d841 --- /dev/null +++ b/expr/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (expr.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, expr.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = expr; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/expr/expr.1 b/expr/expr.1 new file mode 100644 index 0000000..c4f2280 --- /dev/null +++ b/expr/expr.1 @@ -0,0 +1,105 @@ +.\" $NetBSD: expr.1,v 1.10 1997/10/20 08:51:56 enami Exp $ +.\" +.\" Written by J.T. Conklin . +.\" Public domain. +.\" +.Dd July 3, 1993 +.Dt EXPR 1 +.Os +.Sh NAME +.Nm expr +.Nd evaluate expression +.Sh SYNOPSIS +.Nm +.Ar expression +.Sh DESCRIPTION +The +.Nm +utility evaluates +.Ar expression +and writes the result on standard output. +.Pp +All operators are separate arguments to the +.Nm +utility. +Characters special to the command interpreter must be escaped. +.Pp +Operators are listed below in order of increasing precedence. +Operators with equal precedence are grouped within { } symbols. +.Bl -tag -width indent +.It Ar expr1 Li | Ar expr2 +Returns the evaluation of +.Ar expr1 +if it is neither an empty string nor zero; +otherwise, returns the evaluation of +.Ar expr2 . +.It Ar expr1 Li & Ar expr2 +Returns the evaluation of +.Ar expr1 +if neither expression evaluates to an empty string or zero; +otherwise, returns zero. +.It Ar expr1 Li "{=, >, >=, <, <=, !=}" Ar expr2 +Returns the results of integer comparison if both arguments are integers; +otherwise, returns the results of string comparison using the locale-specific +collation sequence. +The result of each comparison is 1 if the specified relation is true, +or 0 if the relation is false. +.It Ar expr1 Li "{+, -}" Ar expr2 +Returns the results of addition or subtraction of integer-valued arguments. +.It Ar expr1 Li "{*, /, %}" Ar expr2 +Returns the results of multiplication, integer division, or remainder of integer-valued arguments. +.It Ar expr1 Li : Ar expr2 +The +.Dq \: +operator matches +.Ar expr1 +against +.Ar expr2 , +which must be a regular expression. The regular expression is anchored +to the beginning of the string with an implicit +.Dq ^ . +.Pp +If the match succeeds and the pattern contains at least one regular +expression subexpression +.Dq "\e(...\e)" , +the string corresponding to +.Dq "\e1" +is returned; +otherwise the matching operator returns the number of characters matched. +If the match fails and the pattern contains a regular expression subexpression +the null string is returned; +otherwise 0. +.El +.Pp +Parentheses are used for grouping in the usual manner. +.Sh EXAMPLES +.Bl -enum +.It +The following example adds one to the variable a. +.Dl a=`expr $a + 1` +.It +The following example returns the filename portion of a pathname stored +in variable a. The // characters act to eliminate ambiguity with the +division operator. +.Dl expr "//$a" Li : '.*/\e(.*\e)' +.It +The following example returns the number of characters in variable a. +.Dl expr $a Li : '.*' +.El +.Sh DIAGNOSTICS +The +.Nm +utility exits with one of the following values: +.Bl -tag -width Ds -compact +.It 0 +the expression is neither an empty string nor 0. +.It 1 +the expression is an empty string or 0. +.It 2 +the expression is invalid. +.El +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2 . diff --git a/expr/expr.c b/expr/expr.c new file mode 100644 index 0000000..5323427 --- /dev/null +++ b/expr/expr.c @@ -0,0 +1,548 @@ +/* $NetBSD: expr.c,v 1.9 1998/07/28 11:41:48 mycroft Exp $ */ + +/* + * Written by J.T. Conklin . + * Public domain. + */ + +#include +#include +#include +#include +#include +#include +#include + + +enum token { + OR, AND, EQ, LT, GT, ADD, SUB, MUL, DIV, MOD, MATCH, RP, LP, + NE, LE, GE, OPERAND, EOI +}; + +struct val { + enum { + integer, + string + } type; + + union { + char *s; + int i; + } u; +}; + +enum token token; +struct val *tokval; +char **av; + +struct val *make_int __P((int)); +struct val *make_str __P((char *)); +void free_value __P((struct val *)); +int is_integer __P((struct val *, int *)); +int to_integer __P((struct val *)); +void to_string __P((struct val *)); +int is_zero_or_null __P((struct val *)); +void nexttoken __P((void)); +void error __P((void)) __attribute__((__noreturn__)); +struct val *eval6 __P((void)); +struct val *eval5 __P((void)); +struct val *eval4 __P((void)); +struct val *eval3 __P((void)); +struct val *eval2 __P((void)); +struct val *eval1 __P((void)); +struct val *eval0 __P((void)); +int main __P((int, char **)); + + +struct val * +make_int(i) + int i; +{ + struct val *vp; + + vp = (struct val *) malloc(sizeof(*vp)); + if (vp == NULL) { + err(2, "%s", ""); + } + vp->type = integer; + vp->u.i = i; + return vp; +} + + +struct val * +make_str(s) + char *s; +{ + struct val *vp; + + vp = (struct val *) malloc(sizeof(*vp)); + if (vp == NULL || ((vp->u.s = strdup(s)) == NULL)) { + err(2, "%s", ""); + } + vp->type = string; + return vp; +} + + +void +free_value(vp) + struct val *vp; +{ + if (vp->type == string) + free(vp->u.s); + free(vp); +} + + +/* determine if vp is an integer; if so, return it's value in *r */ +int +is_integer(vp, r) + struct val *vp; + int *r; +{ + char *s; + int neg; + int i; + + if (vp->type == integer) { + *r = vp->u.i; + return 1; + } + + /* + * POSIX.2 defines an "integer" as an optional unary minus + * followed by digits. + */ + s = vp->u.s; + i = 0; + + neg = (*s == '-'); + if (neg) + s++; + + while (*s) { + if (!isdigit(*s)) + return 0; + + i *= 10; + i += *s - '0'; + + s++; + } + + if (neg) + i *= -1; + + *r = i; + return 1; +} + + +/* coerce to vp to an integer */ +int +to_integer(vp) + struct val *vp; +{ + int r; + + if (vp->type == integer) + return 1; + + if (is_integer(vp, &r)) { + free(vp->u.s); + vp->u.i = r; + vp->type = integer; + return 1; + } + + return 0; +} + + +/* coerce to vp to an string */ +void +to_string(vp) + struct val *vp; +{ + char *tmp; + + if (vp->type == string) + return; + + tmp = malloc(25); + if (tmp == NULL) { + err(2, "%s", ""); + } + (void)snprintf(tmp, 25, "%d", vp->u.i); + vp->type = string; + vp->u.s = tmp; +} + +int +is_zero_or_null(vp) + struct val *vp; +{ + if (vp->type == integer) + return (vp->u.i == 0); + else + return (*vp->u.s == 0 || (to_integer(vp) && vp->u.i == 0)); + /* NOTREACHED */ +} + +void +nexttoken() +{ + char *p; + + if ((p = *av) == NULL) { + token = EOI; + return; + } + av++; + + if (p[0] != '\0') { + if (p[1] == '\0') { + const char *x = "|&=<>+-*/%:()"; + char *i; /* index */ + + if ((i = strchr(x, *p)) != NULL) { + token = i - x; + return; + } + } else if (p[1] == '=' && p[2] == '\0') { + switch (*p) { + case '<': + token = LE; + return; + case '>': + token = GE; + return; + case '!': + token = NE; + return; + } + } + } + tokval = make_str(p); + token = OPERAND; + return; +} + +void +error() +{ + errx(2, "syntax error"); + /* NOTREACHED */ +} + +struct val * +eval6() +{ + struct val *v; + + if (token == OPERAND) { + nexttoken(); + return tokval; + + } else if (token == RP) { + nexttoken(); + v = eval0(); + + if (token != LP) + error(); + nexttoken(); + return v; + } else { + error(); + } + /* NOTREACHED */ +} + +/* Parse and evaluate match (regex) expressions */ +struct val * +eval5() +{ + regex_t rp; + regmatch_t rm[2]; + char errbuf[256]; + int eval; + struct val *l, *r; + struct val *v; + + l = eval6(); + while (token == MATCH) { + nexttoken(); + r = eval6(); + + /* coerce to both arguments to strings */ + to_string(l); + to_string(r); + + /* compile regular expression */ + if ((eval = regcomp(&rp, r->u.s, 0)) != 0) { + (void)regerror(eval, &rp, errbuf, sizeof(errbuf)); + errx(2, "%s", errbuf); + } + + /* compare string against pattern -- remember that patterns + are anchored to the beginning of the line */ + if (regexec(&rp, l->u.s, 2, rm, 0) == 0 && rm[0].rm_so == 0) { + if (rm[1].rm_so >= 0) { + *(l->u.s + rm[1].rm_eo) = '\0'; + v = make_str(l->u.s + rm[1].rm_so); + + } else { + v = make_int((int)(rm[0].rm_eo - rm[0].rm_so)); + } + } else { + if (rp.re_nsub == 0) { + v = make_int(0); + } else { + v = make_str(""); + } + } + + /* free arguments and pattern buffer */ + free_value(l); + free_value(r); + regfree(&rp); + + l = v; + } + + return l; +} + +/* Parse and evaluate multiplication and division expressions */ +struct val * +eval4() +{ + struct val *l, *r; + enum token op; + + l = eval5(); + while ((op = token) == MUL || op == DIV || op == MOD) { + nexttoken(); + r = eval5(); + + if (!to_integer(l) || !to_integer(r)) { + errx(2, "non-numeric argument"); + } + + if (op == MUL) { + l->u.i *= r->u.i; + } else { + if (r->u.i == 0) { + errx(2, "division by zero"); + } + if (op == DIV) { + l->u.i /= r->u.i; + } else { + l->u.i %= r->u.i; + } + } + + free_value(r); + } + + return l; +} + +/* Parse and evaluate addition and subtraction expressions */ +struct val * +eval3() +{ + struct val *l, *r; + enum token op; + + l = eval4(); + while ((op = token) == ADD || op == SUB) { + nexttoken(); + r = eval4(); + + if (!to_integer(l) || !to_integer(r)) { + errx(2, "non-numeric argument"); + } + + if (op == ADD) { + l->u.i += r->u.i; + } else { + l->u.i -= r->u.i; + } + + free_value(r); + } + + return l; +} + +/* Parse and evaluate comparison expressions */ +struct val * +eval2() +{ + struct val *l, *r; + enum token op; + int v = 0; /* pacify gcc */ + int li, ri; + + l = eval3(); + while ((op = token) == EQ || op == NE || op == LT || op == GT || op == LE || op == GE) { + nexttoken(); + r = eval3(); + + if (is_integer(l, &li) && is_integer(r, &ri)) { + switch (op) { + case GT: + v = (li > ri); + break; + case GE: + v = (li >= ri); + break; + case LT: + v = (li < ri); + break; + case LE: + v = (li <= ri); + break; + case EQ: + v = (li == ri); + break; + case NE: + v = (li != ri); + break; + case MOD: + case EOI: + case OPERAND: + case LP: + case RP: + case MATCH: + case DIV: + case MUL: + case SUB: + case ADD: + case AND: + case OR: + /* Can't happen */ + abort(); + break; + } + } else { + to_string(l); + to_string(r); + + switch (op) { + case GT: + v = (strcoll(l->u.s, r->u.s) > 0); + break; + case GE: + v = (strcoll(l->u.s, r->u.s) >= 0); + break; + case LT: + v = (strcoll(l->u.s, r->u.s) < 0); + break; + case LE: + v = (strcoll(l->u.s, r->u.s) <= 0); + break; + case EQ: + v = (strcoll(l->u.s, r->u.s) == 0); + break; + case NE: + v = (strcoll(l->u.s, r->u.s) != 0); + break; + case MUL: + case SUB: + case ADD: + case AND: + case OR: + case DIV: + case OPERAND: + case EOI: + case MOD: + case RP: + case MATCH: + case LP: + /* Can't happen */ + abort(); + break; + } + } + + free_value(l); + free_value(r); + l = make_int(v); + } + + return l; +} + +/* Parse and evaluate & expressions */ +struct val * +eval1() +{ + struct val *l, *r; + + l = eval2(); + while (token == AND) { + nexttoken(); + r = eval2(); + + if (is_zero_or_null(l) || is_zero_or_null(r)) { + free_value(l); + free_value(r); + l = make_int(0); + } else { + free_value(r); + } + } + + return l; +} + +/* Parse and evaluate | expressions */ +struct val * +eval0() +{ + struct val *l, *r; + + l = eval1(); + while (token == OR) { + nexttoken(); + r = eval1(); + + if (is_zero_or_null(l)) { + free_value(l); + l = r; + } else { + free_value(r); + } + } + + return l; +} + + +int +main(argc, argv) + int argc; + char **argv; +{ + struct val *vp; + + (void) setlocale(LC_ALL, ""); + av = argv + 1; + + nexttoken(); + vp = eval0(); + + if (token != EOI) + error(); + + if (vp->type == integer) + (void)printf("%d\n", vp->u.i); + else + (void)printf("%s\n", vp->u.s); + + exit(is_zero_or_null(vp)); + /* NOTREACHED */ +} diff --git a/false/Makefile b/false/Makefile new file mode 100644 index 0000000..480c66f --- /dev/null +++ b/false/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = false + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = false.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble false.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/false/Makefile.postamble b/false/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/false/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/false/Makefile.preamble b/false/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/false/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/false/PB.project b/false/PB.project new file mode 100644 index 0000000..bdc6079 --- /dev/null +++ b/false/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (false.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, false.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = false; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/false/false.1 b/false/false.1 new file mode 100644 index 0000000..f7b07eb --- /dev/null +++ b/false/false.1 @@ -0,0 +1,60 @@ +.\" $NetBSD: false.1,v 1.5 1997/10/18 14:46:54 lukem Exp $ +.\" +.\" Copyright (c) 1983, 1990 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)false.1 6.6 (Berkeley) 7/24/91 +.\" $NetBSD: false.1,v 1.5 1997/10/18 14:46:54 lukem Exp $ +.\" +.Dd July 24, 1991 +.Dt FALSE 1 +.Os BSD 4.2 +.Sh NAME +.Nm false +.Nd Return false value. +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +utility always exits with a nonzero exit code. +.Sh SEE ALSO +.Xr csh 1 , +.Xr sh 1 , +.Xr true 1 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . diff --git a/false/false.c b/false/false.c new file mode 100644 index 0000000..9c29522 --- /dev/null +++ b/false/false.c @@ -0,0 +1 @@ +int main () { exit(1); } \ No newline at end of file diff --git a/find/Makefile b/find/Makefile new file mode 100644 index 0000000..2deb864 --- /dev/null +++ b/find/Makefile @@ -0,0 +1,50 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = find + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = extern.h find.h + +CFILES = find.c function.c ls.c main.c misc.c operator.c option.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble find.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/find/Makefile.postamble b/find/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/find/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/find/Makefile.preamble b/find/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/find/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/find/PB.project b/find/PB.project new file mode 100644 index 0000000..4cc1f6a --- /dev/null +++ b/find/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (extern.h, find.h); + OTHER_LINKED = (find.c, function.c, ls.c, main.c, misc.c, operator.c, option.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, find.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = find; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/find/extern.h b/find/extern.h new file mode 100644 index 0000000..013fa5f --- /dev/null +++ b/find/extern.h @@ -0,0 +1,83 @@ +/* $NetBSD: extern.h,v 1.8 1998/02/21 22:47:20 christos Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)extern.h 8.3 (Berkeley) 4/16/94 + */ + +#include + +void brace_subst __P((char *, char **, char *, int)); +void *emalloc __P((unsigned int)); +PLAN *find_create __P((char ***)); +int find_execute __P((PLAN *, char **)); +PLAN *find_formplan __P((char **)); +int f_expr __P((PLAN *, FTSENT *)); +PLAN *not_squish __P((PLAN *)); +PLAN *or_squish __P((PLAN *)); +PLAN *paren_squish __P((PLAN *)); +struct stat; +void printlong __P((char *, char *, struct stat *)); +int queryuser __P((char **)); + +PLAN *c_atime __P((char ***, int)); +PLAN *c_ctime __P((char ***, int)); +PLAN *c_depth __P((char ***, int)); +PLAN *c_exec __P((char ***, int)); +PLAN *c_follow __P((char ***, int)); +PLAN *c_fstype __P((char ***, int)); +PLAN *c_group __P((char ***, int)); +PLAN *c_inum __P((char ***, int)); +PLAN *c_links __P((char ***, int)); +PLAN *c_ls __P((char ***, int)); +PLAN *c_name __P((char ***, int)); +PLAN *c_newer __P((char ***, int)); +PLAN *c_nogroup __P((char ***, int)); +PLAN *c_nouser __P((char ***, int)); +PLAN *c_path __P((char ***, int)); +PLAN *c_perm __P((char ***, int)); +PLAN *c_print __P((char ***, int)); +PLAN *c_print0 __P((char ***, int)); +PLAN *c_prune __P((char ***, int)); +PLAN *c_size __P((char ***, int)); +PLAN *c_type __P((char ***, int)); +PLAN *c_user __P((char ***, int)); +PLAN *c_xdev __P((char ***, int)); +PLAN *c_openparen __P((char ***, int)); +PLAN *c_closeparen __P((char ***, int)); +PLAN *c_mtime __P((char ***, int)); +PLAN *c_not __P((char ***, int)); +PLAN *c_or __P((char ***, int)); +PLAN *c_null __P((char ***, int)); + +extern int ftsoptions, isdeprecated, isdepth, isoutput, isxargs; diff --git a/find/find.1 b/find/find.1 new file mode 100644 index 0000000..9692337 --- /dev/null +++ b/find/find.1 @@ -0,0 +1,482 @@ +.\" $NetBSD: find.1,v 1.14 1998/05/27 13:15:30 msaitoh Exp $ +.\" +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)find.1 8.7 (Berkeley) 5/9/95 +.\" +.Dd May 9, 1995 +.Dt FIND 1 +.Os +.Sh NAME +.Nm find +.Nd walk a file hierarchy +.Sh SYNOPSIS +.Nm find +.Op Fl H | Fl L | Fl P +.Op Fl Xdx +.Op Fl f Ar file +.Op Ar file ... +.Ar expression +.Sh DESCRIPTION +.Nm +recursively descends the directory tree for each +.Ar file +listed, evaluating an +.Ar expression +(composed of the ``primaries'' and ``operands'' listed below) in terms +of each file in the tree. +.Pp +The options are as follows: +.Pp +.Bl -tag -width Ds +.It Fl H +The +.Fl H +option causes the file information and file type (see +.Xr stat 2 ) , +returned for each symbolic link encountered on the command line to be +those of the file referenced by the link, not the link itself. +If the referenced file does not exist, the file information and type will +be for the link itself. File information of all symbolic links not on +the command line is that of the link itself. +.It Fl L +The +.Fl L +option causes the file information and file type (see +.Xr stat 2) +returned for each symbolic link to be those of the file referenced by the +link, not the link itself. +If the referenced file does not exist, the file information and type will +be for the link itself. +.It Fl P +The +.Fl P +option causes the file information and file type (see +.Xr stat 2) +returned for each symbolic link to be those of the link itself. +.It Fl X +The +.Fl X +option is a modification to permit +.Nm +to be safely used in conjunction with +.Xr xargs 1 . +If a file name contains any of the delimiting characters used by +.Xr xargs , +a diagnostic message is displayed on standard error, and the file +is skipped. +The delimiting characters include single (`` ' '') and double (`` " '') +quotes, backslash (``\e''), space, tab and newline characters. +.It Fl d +The +.Fl d +option causes +.Nm +to perform a depth\-first traversal, i.e. directories +are visited in post\-order and all entries in a directory will be acted +on before the directory itself. +By default, +.Nm +visits directories in pre\-order, i.e. before their contents. +Note, the default is +.Ar not +a breadth\-first traversal. +.It Fl f +The +.Fl f +option specifies a file hierarchy for +.Nm +to traverse. +File hierarchies may also be specified as the operands immediately +following the options. +.It Fl h +The +.Fl h +option causes the file information and file type (see +.Xr stat 2 ) , +returned for each symbolic link to be those of the file referenced by the +link, not the link itself. +If the referenced file does not exist, the file information and type will +be for the link itself. +.It Fl x +The +.Fl x +option prevents +.Nm +from descending into directories that have a device number different +than that of the file from which the descent began. +.El +.Sh PRIMARIES +.Bl -tag -width Ds +.It Ic -atime Ar n +True if the difference between the file last access time and the time +.Nm +was started, rounded up to the next full 24\-hour period, is +.Ar n +24\-hour periods. +.It Ic -ctime Ar n +True if the difference between the time of last change of file status +information and the time +.Nm +was started, rounded up to the next full 24\-hour period, is +.Ar n +24\-hour periods. +.It Ic -exec Ar utility Op argument ... ; +True if the program named +.Ar utility +returns a zero value as its exit status. +Optional arguments may be passed to the utility. +The expression must be terminated by a semicolon (``;''). +If the string ``{}'' appears anywhere in the utility name or the +arguments it is replaced by the pathname of the current file. +.Ar Utility +will be executed from the directory from which +.Nm +was executed. +.It Ic -follow +Follow symbolic links. +.It Ic -fstype Ar type +True if the file is contained in a file system of type +.Ar type . +The +.Xr sysctl 8 +command can be used to find out the types of filesystems +that are available on the system: +.Bd -literal -offset indent +sysctl vfs +.Ed +In addition, there are two pseudo-types, ``local'' and ``rdonly''. +The former matches any file system physically mounted on the system where +the +.Nm +is being executed, and the latter matches any file system which is +mounted read-only. +.It Ic -group Ar gname +True if the file belongs to the group +.Ar gname . +If +.Ar gname +is numeric and there is no such group name, then +.Ar gname +is treated as a group id. +.It Ic -inum Ar n +True if the file has inode number +.Ar n . +.It Ic -links Ar n +True if the file has +.Ar n +links. +.It Ic -ls +This primary always evaluates to true. +The following information for the current file is written to standard output: +its inode number, size in 512\-byte blocks, file permissions, number of hard +links, owner, group, size in bytes, last modification time, and pathname. +If the file is a block or character special file, the major and minor numbers +will be displayed instead of the size in bytes. +If the file is a symbolic link, the pathname of the linked\-to file will be +displayed preceded by ``\->''. +The format is identical to that produced by ``ls \-dgils''. +.It Ic -mtime Ar n +True if the difference between the file last modification time and the time +.Nm +was started, rounded up to the next full 24\-hour period, is +.Ar n +24\-hour periods. +.It Ic \&-ok Ar utility Op argument ... ; +The +.Ic \&-ok +primary is identical to the +.Ic -exec +primary with the exception that +.Nm +requests user affirmation for the execution of the utility by printing +a message to the terminal and reading a response. +If the response is other than ``y'' the command is not executed and the +value of the +.Ar \&ok +expression is false. +.It Ic -name Ar pattern +True if the last component of the pathname being examined matches +.Ar pattern . +Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') +may be used as part of +.Ar pattern . +These characters may be matched explicitly by escaping them with a +backslash (``\e''). +.It Ic -newer Ar file +True if the current file has a more recent last modification time than +.Ar file . +.It Ic -nouser +True if the file belongs to an unknown user. +.It Ic -nogroup +True if the file belongs to an unknown group. +.It Ic -path Ar pattern +True if the pathname being examined matches +.Ar pattern . +Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') +may be used as part of +.Ar pattern . +These characters may be matched explicitly by escaping them with a +backslash (``\e''). +Slashes (``/'') are treated as normal characters and do not have to be +matched explicitly. +.It Ic -perm Op Fl Ns Ar mode +The +.Ar mode +may be either symbolic (see +.Xr chmod 1 ) +or an octal number. +If the mode is symbolic, a starting value of zero is assumed and the +mode sets or clears permissions without regard to the process' file mode +creation mask. +If the mode is octal, only bits 07777 +.Pf ( Dv S_ISUID +| +.Dv S_ISGID +| +.Dv S_ISTXT +| +.Dv S_IRWXU +| +.Dv S_IRWXG +| +.Dv S_IRWXO ) +of the file's mode bits participate +in the comparison. +If the mode is preceded by a dash (``\-''), this primary evaluates to true +if at least all of the bits in the mode are set in the file's mode bits. +If the mode is not preceded by a dash, this primary evaluates to true if +the bits in the mode exactly match the file's mode bits. +Note, the first character of a symbolic mode may not be a dash (``\-''). +.It Ic -print +This primary always evaluates to true. +It prints the pathname of the current file to standard output, followed +by a newline character. +If none of +.Ic -exec , +.Ic -ls , +.Ic -ok , +nor +.Ic -print0 +is specified, the given expression shall be effectively replaced by +.Cm \&( Ns Ar given\& expression Ns Cm \&) +.Ic -print . +.It Ic -print0 +This primary always evaluates to true. +It prints the pathname of the current file to standard output, followed +by a null character. +.It Ic -prune +This primary always evaluates to true. +It causes +.Nm +to not descend into the current file. +Note, the +.Ic -prune +primary has no effect if the +.Fl d +option was specified. +.It Ic -size Ar n Ns Op Cm c +True if the file's size, rounded up, in 512\-byte blocks is +.Ar n . +If +.Ar n +is followed by a ``c'', then the primary is true if the +file's size is +.Ar n +bytes. +.It Ic -type Ar t +True if the file is of the specified type. +Possible file types are as follows: +.Pp +.Bl -tag -width flag -offset indent -compact +.It Cm W +whiteout +.It Cm b +block special +.It Cm c +character special +.It Cm d +directory +.It Cm f +regular file +.It Cm l +symbolic link +.It Cm p +FIFO +.It Cm s +socket +.El +.Pp +.It Ic -user Ar uname +True if the file belongs to the user +.Ar uname . +If +.Ar uname +is numeric and there is no such user name, then +.Ar uname +is treated as a user id. +.El +.Pp +All primaries which take a numeric argument allow the number to be +preceded by a plus sign (``+'') or a minus sign (``\-''). +A preceding plus sign means ``more than n'', a preceding minus sign means +``less than n'' and neither means ``exactly n'' . +.Sh OPERATORS +The primaries may be combined using the following operators. +The operators are listed in order of decreasing precedence. +.Bl -tag -width (expression) +.It Cm \&( Ns Ar expression Ns Cm \&) +This evaluates to true if the parenthesized expression evaluates to +true. +.Pp +.It Cm \&! Ns Ar expression +This is the unary +.Tn NOT +operator. +It evaluates to true if the expression is false. +.Pp +.It Ar expression Cm -and Ar expression +.It Ar expression expression +The +.Cm -and +operator is the logical +.Tn AND +operator. +As it is implied by the juxtaposition of two expressions it does not +have to be specified. +The expression evaluates to true if both expressions are true. +The second expression is not evaluated if the first expression is false. +.Pp +.It Ar expression Cm -or Ar expression +The +.Cm -or +operator is the logical +.Tn OR +operator. +The expression evaluates to true if either the first or the second expression +is true. +The second expression is not evaluated if the first expression is true. +.El +.Pp +All operands and primaries must be separate arguments to +.Nm "" . +Primaries which themselves take arguments expect each argument +to be a separate argument to +.Nm "" . +.Sh EXAMPLES +.Pp +The following examples are shown as given to the shell: +.Bl -tag -width findx +.It Li "find / \e! -name \*q*.c\*q -print" +Print out a list of all the files whose names do not end in ``.c''. +.It Li "find / -newer ttt -user wnj -print" +Print out a list of all the files owned by user ``wnj'' that are newer +than the file ``ttt''. +.It Li "find / \e! \e( -newer ttt -user wnj \e) -print" +Print out a list of all the files which are not both newer than ``ttt'' +and owned by ``wnj''. +.It Li "find / \e( -newer ttt -or -user wnj \e) -print" +Print out a list of all the files that are either owned by ``wnj'' or +that are newer than ``ttt''. +.El +.Sh SEE ALSO +.Xr chmod 1 , +.Xr locate 1 , +.Xr stat 2 , +.Xr fts 3 , +.Xr getpwent 3 , +.Xr getgrent 3 , +.Xr strmode 3 , +.Xr symlink 7 +.Sh STANDARDS +The +.Nm +utility syntax is a superset of the syntax specified by the +.St -p1003.2 +standard. +.Pp +The options and the +.Ic -follow , +.Ic -fstype , +.Ic -inum , +.Ic -links , +.Ic -ls +and +.Ic -print0 +primaries are extensions to +.St -p1003.2 . +.Pp +Historically, the +.Fl d , +.Fl h +and +.Fl x +options were implemented using the primaries ``\-depth'', ``\-follow'', +and ``\-xdev''. +These primaries always evaluated to true. +As they were really global variables that took effect before the traversal +began, some legal expressions could have unexpected results. +An example is the expression ``\-print \-o \-depth''. +As \-print always evaluates to true, the standard order of evaluation +implies that \-depth would never be evaluated. +This is not the case. +.Pp +The operator ``-or'' was implemented as ``\-o'', and the operator ``-and'' +was implemented as ``\-a''. +.Pp +Historic implementations of the +.Ic -exec +and +.Ic -ok +primaries did not replace the string ``{}'' in the utility name or the +utility arguments if it had preceding or following non-whitespace characters. +This version replaces it no matter where in the utility name or arguments +it appears. +.Sh BUGS +The special characters used by +.Nm +are also special characters to many shell programs. +In particular, the characters ``*'', ``['', ``]'', ``?'', ``('', ``)'', +``!'', ``\e'' and ``;'' may have to be escaped from the shell. +.Pp +As there is no delimiter separating options and file names or file +names and the +.Ar expression , +it is difficult to specify files named ``-xdev'' or ``!''. +These problems are handled by the +.Fl f +option and the +.Xr getopt 3 +``--'' construct. diff --git a/find/find.c b/find/find.c new file mode 100644 index 0000000..a1672ac --- /dev/null +++ b/find/find.c @@ -0,0 +1,211 @@ +/* $NetBSD: find.c,v 1.11 1998/02/21 22:47:20 christos Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Cimarron D. Taylor of the University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)find.c 8.5 (Berkeley) 8/5/94"; +#else +__RCSID("$NetBSD: find.c,v 1.11 1998/02/21 22:47:20 christos Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "find.h" + +/* + * find_formplan -- + * process the command line and create a "plan" corresponding to the + * command arguments. + */ +PLAN * +find_formplan(argv) + char **argv; +{ + PLAN *plan, *tail, *new; + + /* + * for each argument in the command line, determine what kind of node + * it is, create the appropriate node type and add the new plan node + * to the end of the existing plan. The resulting plan is a linked + * list of plan nodes. For example, the string: + * + * % find . -name foo -newer bar -print + * + * results in the plan: + * + * [-name foo]--> [-newer bar]--> [-print] + * + * in this diagram, `[-name foo]' represents the plan node generated + * by c_name() with an argument of foo and `-->' represents the + * plan->next pointer. + */ + for (plan = tail = NULL; *argv;) { + if (!(new = find_create(&argv))) + continue; + if (plan == NULL) + tail = plan = new; + else { + tail->next = new; + tail = new; + } + } + + /* + * if the user didn't specify one of -print, -ok or -exec, then -print + * is assumed so we bracket the current expression with parens, if + * necessary, and add a -print node on the end. + */ + if (!isoutput) { + if (plan == NULL) { + new = c_print(NULL, 0); + tail = plan = new; + } else { + new = c_openparen(NULL, 0); + new->next = plan; + plan = new; + new = c_closeparen(NULL, 0); + tail->next = new; + tail = new; + new = c_print(NULL, 0); + tail->next = new; + tail = new; + } + } + + /* + * the command line has been completely processed into a search plan + * except for the (, ), !, and -o operators. Rearrange the plan so + * that the portions of the plan which are affected by the operators + * are moved into operator nodes themselves. For example: + * + * [!]--> [-name foo]--> [-print] + * + * becomes + * + * [! [-name foo] ]--> [-print] + * + * and + * + * [(]--> [-depth]--> [-name foo]--> [)]--> [-print] + * + * becomes + * + * [expr [-depth]-->[-name foo] ]--> [-print] + * + * operators are handled in order of precedence. + */ + + plan = paren_squish(plan); /* ()'s */ + plan = not_squish(plan); /* !'s */ + plan = or_squish(plan); /* -o's */ + return (plan); +} + +FTS *tree; /* pointer to top of FTS hierarchy */ + +/* + * find_execute -- + * take a search plan and an array of search paths and executes the plan + * over all FTSENT's returned for the given search paths. + */ +int +find_execute(plan, paths) + PLAN *plan; /* search plan */ + char **paths; /* array of pathnames to traverse */ +{ + register FTSENT *entry; + PLAN *p; + int rval; + + if (!(tree = fts_open(paths, ftsoptions, NULL))) + err(1, "ftsopen"); + + for (rval = 0; (entry = fts_read(tree)) != NULL; ) { + switch (entry->fts_info) { + case FTS_D: + if (isdepth) + continue; + break; + case FTS_DP: + if (!isdepth) + continue; + break; + case FTS_DNR: + case FTS_ERR: + case FTS_NS: + (void)fflush(stdout); + warnx("%s: %s", + entry->fts_path, strerror(entry->fts_errno)); + rval = 1; + continue; +#ifdef FTS_W + case FTS_W: + continue; +#endif /* FTS_W */ + } +#define BADCH " \t\n\\'\"" + if (isxargs && strpbrk(entry->fts_path, BADCH)) { + (void)fflush(stdout); + warnx("%s: illegal path", entry->fts_path); + rval = 1; + continue; + } + + /* + * Call all the functions in the execution plan until one is + * false or all have been executed. This is where we do all + * the work specified by the user on the command line. + */ + for (p = plan; p && (p->eval)(p, entry); p = p->next) + ; + } + if (errno) + err(1, "fts_read"); + (void)fts_close(tree); + return (rval); +} diff --git a/find/find.h b/find/find.h new file mode 100644 index 0000000..804011f --- /dev/null +++ b/find/find.h @@ -0,0 +1,106 @@ +/* $NetBSD: find.h,v 1.8 1998/02/21 22:47:20 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Cimarron D. Taylor of the University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)find.h 8.1 (Berkeley) 6/6/93 + */ + +/* node type */ +enum ntype { + N_AND = 1, /* must start > 0 */ + N_ATIME, N_CLOSEPAREN, N_CTIME, N_DEPTH, N_EXEC, N_EXPR, N_FOLLOW, + N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MTIME, N_NAME, N_NEWER, + N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH, + N_PERM, N_PRINT, N_PRINT0, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV, +}; + +/* node definition */ +typedef struct _plandata { + struct _plandata *next; /* next node */ + int (*eval) /* node evaluation function */ + __P((struct _plandata *, FTSENT *)); +#define F_EQUAL 1 /* [acm]time inum links size */ +#define F_LESSTHAN 2 +#define F_GREATER 3 +#define F_NEEDOK 1 /* exec ok */ +#define F_MTFLAG 1 /* fstype */ +#define F_MTTYPE 2 +#define F_ATLEAST 1 /* perm */ + int flags; /* private flags */ + enum ntype type; /* plan node type */ + union { + gid_t _g_data; /* gid */ + ino_t _i_data; /* inode */ + mode_t _m_data; /* mode mask */ + nlink_t _l_data; /* link count */ + off_t _o_data; /* file size */ + time_t _t_data; /* time value */ + uid_t _u_data; /* uid */ + short _mt_data; /* mount flags */ + struct _plandata *_p_data[2]; /* PLAN trees */ + struct _ex { + char **_e_argv; /* argv array */ + char **_e_orig; /* original strings */ + int *_e_len; /* allocated length */ + } ex; + char *_a_data[2]; /* array of char pointers */ + char *_c_data; /* char pointer */ + } p_un; +} PLAN; +#define a_data p_un._a_data +#define c_data p_un._c_data +#define i_data p_un._i_data +#define g_data p_un._g_data +#define l_data p_un._l_data +#define m_data p_un._m_data +#define mt_data p_un._mt_data +#define o_data p_un._o_data +#define p_data p_un._p_data +#define t_data p_un._t_data +#define u_data p_un._u_data +#define e_argv p_un.ex._e_argv +#define e_orig p_un.ex._e_orig +#define e_len p_un.ex._e_len + +typedef struct _option { + char *name; /* option name */ + enum ntype token; /* token type */ + PLAN *(*create) /* create function */ + __P((char ***, int)); + int arg; /* function needs arg */ +} OPTION; + +#include "extern.h" diff --git a/find/function.c b/find/function.c new file mode 100644 index 0000000..efa1abe --- /dev/null +++ b/find/function.c @@ -0,0 +1,1187 @@ +/* $NetBSD: function.c,v 1.24 1998/02/21 22:47:20 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Cimarron D. Taylor of the University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95"; +#else +__RCSID("$NetBSD: function.c,v 1.24 1998/02/21 22:47:20 christos Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "find.h" + +#define COMPARE(a, b) { \ + switch (plan->flags) { \ + case F_EQUAL: \ + return (a == b); \ + case F_LESSTHAN: \ + return (a < b); \ + case F_GREATER: \ + return (a > b); \ + default: \ + abort(); \ + } \ +} + +static long find_parsenum __P((PLAN *, char *, char *, char *)); + int f_always_true __P((PLAN *, FTSENT *)); + int f_atime __P((PLAN *, FTSENT *)); + int f_ctime __P((PLAN *, FTSENT *)); + int f_exec __P((PLAN *, FTSENT *)); + int f_fstype __P((PLAN *, FTSENT *)); + int f_group __P((PLAN *, FTSENT *)); + int f_inum __P((PLAN *, FTSENT *)); + int f_links __P((PLAN *, FTSENT *)); + int f_ls __P((PLAN *, FTSENT *)); + int f_mtime __P((PLAN *, FTSENT *)); + int f_name __P((PLAN *, FTSENT *)); + int f_newer __P((PLAN *, FTSENT *)); + int f_nogroup __P((PLAN *, FTSENT *)); + int f_nouser __P((PLAN *, FTSENT *)); + int f_path __P((PLAN *, FTSENT *)); + int f_perm __P((PLAN *, FTSENT *)); + int f_print __P((PLAN *, FTSENT *)); + int f_print0 __P((PLAN *, FTSENT *)); + int f_prune __P((PLAN *, FTSENT *)); + int f_size __P((PLAN *, FTSENT *)); + int f_type __P((PLAN *, FTSENT *)); + int f_user __P((PLAN *, FTSENT *)); + int f_not __P((PLAN *, FTSENT *)); + int f_or __P((PLAN *, FTSENT *)); +static PLAN *palloc __P((enum ntype, int (*) __P((PLAN *, FTSENT *)))); + +/* + * find_parsenum -- + * Parse a string of the form [+-]# and return the value. + */ +static long +find_parsenum(plan, option, vp, endch) + PLAN *plan; + char *option, *vp, *endch; +{ + long value; + char *endchar, *str; /* Pointer to character ending conversion. */ + + /* Determine comparison from leading + or -. */ + str = vp; + switch (*str) { + case '+': + ++str; + plan->flags = F_GREATER; + break; + case '-': + ++str; + plan->flags = F_LESSTHAN; + break; + default: + plan->flags = F_EQUAL; + break; + } + + /* + * Convert the string with strtol(). Note, if strtol() returns zero + * and endchar points to the beginning of the string we know we have + * a syntax error. + */ + value = strtol(str, &endchar, 10); + if (value == 0 && endchar == str) + errx(1, "%s: %s: illegal numeric value", option, vp); + if (endchar[0] && (endch == NULL || endchar[0] != *endch)) + errx(1, "%s: %s: illegal trailing character", option, vp); + if (endch) + *endch = endchar[0]; + return (value); +} + +/* + * The value of n for the inode times (atime, ctime, and mtime) is a range, + * i.e. n matches from (n - 1) to n 24 hour periods. This interacts with + * -n, such that "-mtime -1" would be less than 0 days, which isn't what the + * user wanted. Correct so that -1 is "less than 1". + */ +#define TIME_CORRECT(p, ttype) \ + if ((p)->type == ttype && (p)->flags == F_LESSTHAN) \ + ++((p)->t_data); + +/* + * -atime n functions -- + * + * True if the difference between the file access time and the + * current time is n 24 hour periods. + */ +int +f_atime(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern time_t now; + + COMPARE((now - entry->fts_statp->st_atime + + SECSPERDAY - 1) / SECSPERDAY, plan->t_data); +} + +PLAN * +c_atime(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_ATIME, f_atime); + new->t_data = find_parsenum(new, "-atime", arg, NULL); + TIME_CORRECT(new, N_ATIME); + return (new); +} +/* + * -ctime n functions -- + * + * True if the difference between the last change of file + * status information and the current time is n 24 hour periods. + */ +int +f_ctime(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern time_t now; + + COMPARE((now - entry->fts_statp->st_ctime + + SECSPERDAY - 1) / SECSPERDAY, plan->t_data); +} + +PLAN * +c_ctime(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_CTIME, f_ctime); + new->t_data = find_parsenum(new, "-ctime", arg, NULL); + TIME_CORRECT(new, N_CTIME); + return (new); +} + +/* + * -depth functions -- + * + * Always true, causes descent of the directory hierarchy to be done + * so that all entries in a directory are acted on before the directory + * itself. + */ +int +f_always_true(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + return (1); +} + +PLAN * +c_depth(argvp, isok) + char ***argvp; + int isok; +{ + isdepth = 1; + + return (palloc(N_DEPTH, f_always_true)); +} + +/* + * [-exec | -ok] utility [arg ... ] ; functions -- + * + * True if the executed utility returns a zero value as exit status. + * The end of the primary expression is delimited by a semicolon. If + * "{}" occurs anywhere, it gets replaced by the current pathname. + * The current directory for the execution of utility is the same as + * the current directory when the find utility was started. + * + * The primary -ok is different in that it requests affirmation of the + * user before executing the utility. + */ +int +f_exec(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern int dotfd; + int cnt; + pid_t pid; + int status; + + for (cnt = 0; plan->e_argv[cnt]; ++cnt) + if (plan->e_len[cnt]) + brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt], + entry->fts_path, plan->e_len[cnt]); + + if (plan->flags == F_NEEDOK && !queryuser(plan->e_argv)) + return (0); + + /* don't mix output of command with find output */ + fflush(stdout); + fflush(stderr); + + switch (pid = vfork()) { + case -1: + err(1, "fork"); + /* NOTREACHED */ + case 0: + if (fchdir(dotfd)) { + warn("chdir"); + _exit(1); + } + execvp(plan->e_argv[0], plan->e_argv); + warn("%s", plan->e_argv[0]); + _exit(1); + } + pid = waitpid(pid, &status, 0); + return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status)); +} + +/* + * c_exec -- + * build three parallel arrays, one with pointers to the strings passed + * on the command line, one with (possibly duplicated) pointers to the + * argv array, and one with integer values that are lengths of the + * strings, but also flags meaning that the string has to be massaged. + */ +PLAN * +c_exec(argvp, isok) + char ***argvp; + int isok; +{ + PLAN *new; /* node returned */ + int cnt; + char **argv, **ap, *p; + + isoutput = 1; + + new = palloc(N_EXEC, f_exec); + if (isok) + new->flags = F_NEEDOK; + + for (ap = argv = *argvp;; ++ap) { + if (!*ap) + errx(1, + "%s: no terminating \";\"", isok ? "-ok" : "-exec"); + if (**ap == ';') + break; + } + + cnt = ap - *argvp + 1; + new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *)); + new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *)); + new->e_len = (int *)emalloc((u_int)cnt * sizeof(int)); + + for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) { + new->e_orig[cnt] = *argv; + for (p = *argv; *p; ++p) + if (p[0] == '{' && p[1] == '}') { + new->e_argv[cnt] = emalloc((u_int)MAXPATHLEN); + new->e_len[cnt] = MAXPATHLEN; + break; + } + if (!*p) { + new->e_argv[cnt] = *argv; + new->e_len[cnt] = 0; + } + } + new->e_argv[cnt] = new->e_orig[cnt] = NULL; + + *argvp = argv + 1; + return (new); +} + +/* + * -follow functions -- + * + * Always true, causes symbolic links to be followed on a global + * basis. + */ +PLAN * +c_follow(argvp, isok) + char ***argvp; + int isok; +{ + ftsoptions &= ~FTS_PHYSICAL; + ftsoptions |= FTS_LOGICAL; + + return (palloc(N_FOLLOW, f_always_true)); +} + +/* + * -fstype functions -- + * + * True if the file is of a certain type. + */ +int +f_fstype(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + static dev_t curdev; /* need a guaranteed illegal dev value */ + static int first = 1; + struct statfs sb; + static short val; + static char fstype[MFSNAMELEN]; + char *p, save[2]; + + /* Only check when we cross mount point. */ + if (first || curdev != entry->fts_statp->st_dev) { + curdev = entry->fts_statp->st_dev; + + /* + * Statfs follows symlinks; find wants the link's file system, + * not where it points. + */ + if (entry->fts_info == FTS_SL || + entry->fts_info == FTS_SLNONE) { + if ((p = strrchr(entry->fts_accpath, '/')) != NULL) + ++p; + else + p = entry->fts_accpath; + save[0] = p[0]; + p[0] = '.'; + save[1] = p[1]; + p[1] = '\0'; + + } else + p = NULL; + + if (statfs(entry->fts_accpath, &sb)) + err(1, "%s", entry->fts_accpath); + + if (p) { + p[0] = save[0]; + p[1] = save[1]; + } + + first = 0; + + /* + * Further tests may need both of these values, so + * always copy both of them. + */ + val = sb.f_flags; + strncpy(fstype, sb.f_fstypename, MFSNAMELEN); + } + switch (plan->flags) { + case F_MTFLAG: + return (val & plan->mt_data); + case F_MTTYPE: + return (strncmp(fstype, plan->c_data, MFSNAMELEN) == 0); + default: + abort(); + } +} + +PLAN * +c_fstype(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_FSTYPE, f_fstype); + + switch (*arg) { + case 'l': + if (!strcmp(arg, "local")) { + new->flags = F_MTFLAG; + new->mt_data = MNT_LOCAL; + return (new); + } + break; + case 'r': + if (!strcmp(arg, "rdonly")) { + new->flags = F_MTFLAG; + new->mt_data = MNT_RDONLY; + return (new); + } + break; + } + + new->flags = F_MTTYPE; + new->c_data = arg; + return (new); +} + +/* + * -group gname functions -- + * + * True if the file belongs to the group gname. If gname is numeric and + * an equivalent of the getgrnam() function does not return a valid group + * name, gname is taken as a group ID. + */ +int +f_group(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + return (entry->fts_statp->st_gid == plan->g_data); +} + +PLAN * +c_group(argvp, isok) + char ***argvp; + int isok; +{ + char *gname = **argvp; + PLAN *new; + struct group *g; + gid_t gid; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + g = getgrnam(gname); + if (g == NULL) { + gid = atoi(gname); + if (gid == 0 && gname[0] != '0') + errx(1, "-group: %s: no such group", gname); + } else + gid = g->gr_gid; + + new = palloc(N_GROUP, f_group); + new->g_data = gid; + return (new); +} + +/* + * -inum n functions -- + * + * True if the file has inode # n. + */ +int +f_inum(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + COMPARE(entry->fts_statp->st_ino, plan->i_data); +} + +PLAN * +c_inum(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_INUM, f_inum); + new->i_data = find_parsenum(new, "-inum", arg, NULL); + return (new); +} + +/* + * -links n functions -- + * + * True if the file has n links. + */ +int +f_links(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + COMPARE(entry->fts_statp->st_nlink, plan->l_data); +} + +PLAN * +c_links(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_LINKS, f_links); + new->l_data = (nlink_t)find_parsenum(new, "-links", arg, NULL); + return (new); +} + +/* + * -ls functions -- + * + * Always true - prints the current entry to stdout in "ls" format. + */ +int +f_ls(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + printlong(entry->fts_path, entry->fts_accpath, entry->fts_statp); + return (1); +} + +PLAN * +c_ls(argvp, isok) + char ***argvp; + int isok; +{ + ftsoptions &= ~FTS_NOSTAT; + isoutput = 1; + + return (palloc(N_LS, f_ls)); +} + +/* + * -mtime n functions -- + * + * True if the difference between the file modification time and the + * current time is n 24 hour periods. + */ +int +f_mtime(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern time_t now; + + COMPARE((now - entry->fts_statp->st_mtime + SECSPERDAY - 1) / + SECSPERDAY, plan->t_data); +} + +PLAN * +c_mtime(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_MTIME, f_mtime); + new->t_data = find_parsenum(new, "-mtime", arg, NULL); + TIME_CORRECT(new, N_MTIME); + return (new); +} + +/* + * -name functions -- + * + * True if the basename of the filename being examined + * matches pattern using Pattern Matching Notation S3.14 + */ +int +f_name(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + return (!fnmatch(plan->c_data, entry->fts_name, 0)); +} + +PLAN * +c_name(argvp, isok) + char ***argvp; + int isok; +{ + char *pattern = **argvp; + PLAN *new; + + (*argvp)++; + new = palloc(N_NAME, f_name); + new->c_data = pattern; + return (new); +} + +/* + * -newer file functions -- + * + * True if the current file has been modified more recently + * then the modification time of the file named by the pathname + * file. + */ +int +f_newer(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + return (entry->fts_statp->st_mtime > plan->t_data); +} + +PLAN * +c_newer(argvp, isok) + char ***argvp; + int isok; +{ + char *filename = **argvp; + PLAN *new; + struct stat sb; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + if (stat(filename, &sb)) + err(1, "%s", filename); + new = palloc(N_NEWER, f_newer); + new->t_data = sb.st_mtime; + return (new); +} + +/* + * -nogroup functions -- + * + * True if file belongs to a user ID for which the equivalent + * of the getgrnam() 9.2.1 [POSIX.1] function returns NULL. + */ +int +f_nogroup(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + + return (group_from_gid(entry->fts_statp->st_gid, 1) ? 0 : 1); +} + +PLAN * +c_nogroup(argvp, isok) + char ***argvp; + int isok; +{ + ftsoptions &= ~FTS_NOSTAT; + + return (palloc(N_NOGROUP, f_nogroup)); +} + +/* + * -nouser functions -- + * + * True if file belongs to a user ID for which the equivalent + * of the getpwuid() 9.2.2 [POSIX.1] function returns NULL. + */ +int +f_nouser(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + + return (user_from_uid(entry->fts_statp->st_uid, 1) ? 0 : 1); +} + +PLAN * +c_nouser(argvp, isok) + char ***argvp; + int isok; +{ + ftsoptions &= ~FTS_NOSTAT; + + return (palloc(N_NOUSER, f_nouser)); +} + +/* + * -path functions -- + * + * True if the path of the filename being examined + * matches pattern using Pattern Matching Notation S3.14 + */ +int +f_path(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + return (!fnmatch(plan->c_data, entry->fts_path, 0)); +} + +PLAN * +c_path(argvp, isok) + char ***argvp; + int isok; +{ + char *pattern = **argvp; + PLAN *new; + + (*argvp)++; + new = palloc(N_NAME, f_path); + new->c_data = pattern; + return (new); +} + +/* + * -perm functions -- + * + * The mode argument is used to represent file mode bits. If it starts + * with a leading digit, it's treated as an octal mode, otherwise as a + * symbolic mode. + */ +int +f_perm(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + mode_t mode; + + mode = entry->fts_statp->st_mode & + (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO); + if (plan->flags == F_ATLEAST) + return ((plan->m_data | mode) == mode); + else + return (mode == plan->m_data); + /* NOTREACHED */ +} + +PLAN * +c_perm(argvp, isok) + char ***argvp; + int isok; +{ + char *perm = **argvp; + PLAN *new; + mode_t *set; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_PERM, f_perm); + + if (*perm == '-') { + new->flags = F_ATLEAST; + ++perm; + } + + if ((set = setmode(perm)) == NULL) + err(1, "-perm: %s: illegal mode string", perm); + + new->m_data = getmode(set, 0); + return (new); +} + +/* + * -print functions -- + * + * Always true, causes the current pathame to be written to + * standard output. + */ +int +f_print(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + (void)printf("%s\n", entry->fts_path); + return (1); +} + +int +f_print0(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + (void)fputs(entry->fts_path, stdout); + (void)fputc('\0', stdout); + return (1); +} + +PLAN * +c_print(argvp, isok) + char ***argvp; + int isok; +{ + isoutput = 1; + + return (palloc(N_PRINT, f_print)); +} + +PLAN * +c_print0(argvp, isok) + char ***argvp; + int isok; +{ + isoutput = 1; + + return (palloc(N_PRINT0, f_print0)); +} + +/* + * -prune functions -- + * + * Prune a portion of the hierarchy. + */ +int +f_prune(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern FTS *tree; + + if (fts_set(tree, entry, FTS_SKIP)) + err(1, "%s", entry->fts_path); + return (1); +} + +PLAN * +c_prune(argvp, isok) + char ***argvp; + int isok; +{ + return (palloc(N_PRUNE, f_prune)); +} + +/* + * -size n[c] functions -- + * + * True if the file size in bytes, divided by an implementation defined + * value and rounded up to the next integer, is n. If n is followed by + * a c, the size is in bytes. + */ +#define FIND_SIZE 512 +static int divsize = 1; + +int +f_size(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + off_t size; + + size = divsize ? (entry->fts_statp->st_size + FIND_SIZE - 1) / + FIND_SIZE : entry->fts_statp->st_size; + COMPARE(size, plan->o_data); +} + +PLAN * +c_size(argvp, isok) + char ***argvp; + int isok; +{ + char *arg = **argvp; + PLAN *new; + char endch; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + new = palloc(N_SIZE, f_size); + endch = 'c'; + new->o_data = find_parsenum(new, "-size", arg, &endch); + if (endch == 'c') + divsize = 0; + return (new); +} + +/* + * -type c functions -- + * + * True if the type of the file is c, where c is b, c, d, p, f or w + * for block special file, character special file, directory, FIFO, + * regular file or whiteout respectively. + */ +int +f_type(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + return ((entry->fts_statp->st_mode & S_IFMT) == plan->m_data); +} + +PLAN * +c_type(argvp, isok) + char ***argvp; + int isok; +{ + char *typestring = **argvp; + PLAN *new; + mode_t mask = (mode_t)0; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + switch (typestring[0]) { +#ifdef S_IFWHT + case 'W': +#ifdef FTS_WHITEOUT + ftsoptions |= FTS_WHITEOUT; +#endif + mask = S_IFWHT; + break; +#endif + case 'b': + mask = S_IFBLK; + break; + case 'c': + mask = S_IFCHR; + break; + case 'd': + mask = S_IFDIR; + break; + case 'f': + mask = S_IFREG; + break; + case 'l': + mask = S_IFLNK; + break; + case 'p': + mask = S_IFIFO; + break; + case 's': + mask = S_IFSOCK; + break; +#ifdef FTS_WHITEOUT + case 'w': + mask = S_IFWHT; + ftsoptions |= FTS_WHITEOUT; + break; +#endif /* FTS_WHITEOUT */ + default: + errx(1, "-type: %s: unknown type", typestring); + } + + new = palloc(N_TYPE, f_type); + new->m_data = mask; + return (new); +} + +/* + * -user uname functions -- + * + * True if the file belongs to the user uname. If uname is numeric and + * an equivalent of the getpwnam() S9.2.2 [POSIX.1] function does not + * return a valid user name, uname is taken as a user ID. + */ +int +f_user(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + return (entry->fts_statp->st_uid == plan->u_data); +} + +PLAN * +c_user(argvp, isok) + char ***argvp; + int isok; +{ + char *username = **argvp; + PLAN *new; + struct passwd *p; + uid_t uid; + + (*argvp)++; + ftsoptions &= ~FTS_NOSTAT; + + p = getpwnam(username); + if (p == NULL) { + uid = atoi(username); + if (uid == 0 && username[0] != '0') + errx(1, "-user: %s: no such user", username); + } else + uid = p->pw_uid; + + new = palloc(N_USER, f_user); + new->u_data = uid; + return (new); +} + +/* + * -xdev functions -- + * + * Always true, causes find not to decend past directories that have a + * different device ID (st_dev, see stat() S5.6.2 [POSIX.1]) + */ +PLAN * +c_xdev(argvp, isok) + char ***argvp; + int isok; +{ + ftsoptions |= FTS_XDEV; + + return (palloc(N_XDEV, f_always_true)); +} + +/* + * ( expression ) functions -- + * + * True if expression is true. + */ +int +f_expr(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + PLAN *p; + int state; + + state = 0; + for (p = plan->p_data[0]; + p && (state = (p->eval)(p, entry)); p = p->next); + return (state); +} + +/* + * N_OPENPAREN and N_CLOSEPAREN nodes are temporary place markers. They are + * eliminated during phase 2 of find_formplan() --- the '(' node is converted + * to a N_EXPR node containing the expression and the ')' node is discarded. + */ +PLAN * +c_openparen(argvp, isok) + char ***argvp; + int isok; +{ + return (palloc(N_OPENPAREN, (int (*) __P((PLAN *, FTSENT *)))-1)); +} + +PLAN * +c_closeparen(argvp, isok) + char ***argvp; + int isok; +{ + return (palloc(N_CLOSEPAREN, (int (*) __P((PLAN *, FTSENT *)))-1)); +} + +/* + * ! expression functions -- + * + * Negation of a primary; the unary NOT operator. + */ +int +f_not(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + PLAN *p; + int state; + + state = 0; + for (p = plan->p_data[0]; + p && (state = (p->eval)(p, entry)); p = p->next); + return (!state); +} + +PLAN * +c_not(argvp, isok) + char ***argvp; + int isok; +{ + return (palloc(N_NOT, f_not)); +} + +/* + * expression -o expression functions -- + * + * Alternation of primaries; the OR operator. The second expression is + * not evaluated if the first expression is true. + */ +int +f_or(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + PLAN *p; + int state; + + state = 0; + for (p = plan->p_data[0]; + p && (state = (p->eval)(p, entry)); p = p->next); + + if (state) + return (1); + + for (p = plan->p_data[1]; + p && (state = (p->eval)(p, entry)); p = p->next); + return (state); +} + +PLAN * +c_or(argvp, isok) + char ***argvp; + int isok; +{ + return (palloc(N_OR, f_or)); +} + +PLAN * +c_null(argvp, isok) + char ***argvp; + int isok; +{ + return NULL; +} + +static PLAN * +palloc(t, f) + enum ntype t; + int (*f) __P((PLAN *, FTSENT *)); +{ + PLAN *new; + + if ((new = malloc(sizeof(PLAN))) == NULL) + err(1, "%s", ""); + new->type = t; + new->eval = f; + new->flags = 0; + new->next = NULL; + return (new); +} diff --git a/find/ls.c b/find/ls.c new file mode 100644 index 0000000..cdce351 --- /dev/null +++ b/find/ls.c @@ -0,0 +1,131 @@ +/* $NetBSD: ls.c,v 1.10 1998/03/03 02:22:40 thorpej Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)ls.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ls.c,v 1.10 1998/03/03 02:22:40 thorpej Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "find.h" + +/* Derived from the print routines in the ls(1) source code. */ + +static void printlink __P((char *)); +static void printtime __P((time_t)); + +void +printlong(name, accpath, sb) + char *name; /* filename to print */ + char *accpath; /* current valid path to filename */ + struct stat *sb; /* stat buffer */ +{ + char modep[15]; + + (void)printf("%6lu %4qd ", (u_long)sb->st_ino, + (long long)sb->st_blocks); + (void)strmode(sb->st_mode, modep); + (void)printf("%s %3u %-*s %-*s ", modep, sb->st_nlink, UT_NAMESIZE, + user_from_uid(sb->st_uid, 0), UT_NAMESIZE, + group_from_gid(sb->st_gid, 0)); + + if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) + (void)printf("%3d, %3d ", major(sb->st_rdev), + minor(sb->st_rdev)); + else + (void)printf("%8qd ", (long long)sb->st_size); + printtime(sb->st_mtime); + (void)printf("%s", name); + if (S_ISLNK(sb->st_mode)) + printlink(accpath); + (void)putchar('\n'); +} + +static void +printtime(ftime) + time_t ftime; +{ + int i; + char *longstring; + + longstring = ctime(&ftime); + for (i = 4; i < 11; ++i) + (void)putchar(longstring[i]); + +#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) + if (ftime + SIXMONTHS > time((time_t *)NULL)) + for (i = 11; i < 16; ++i) + (void)putchar(longstring[i]); + else { + (void)putchar(' '); + for (i = 20; i < 24; ++i) + (void)putchar(longstring[i]); + } + (void)putchar(' '); +} + +static void +printlink(name) + char *name; +{ + int lnklen; + char path[MAXPATHLEN + 1]; + + if ((lnklen = readlink(name, path, MAXPATHLEN)) == -1) { + warn("%s", name); + return; + } + path[lnklen] = '\0'; + (void)printf(" -> %s", path); +} diff --git a/find/main.c b/find/main.c new file mode 100644 index 0000000..ed2f090 --- /dev/null +++ b/find/main.c @@ -0,0 +1,158 @@ +/* $NetBSD: main.c,v 1.10 1998/02/10 21:52:51 cgd Exp $ */ + +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Cimarron D. Taylor of the University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; +#else +__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +__RCSID("$NetBSD: main.c,v 1.10 1998/02/10 21:52:51 cgd Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "find.h" + +time_t now; /* time find was run */ +int dotfd; /* starting directory */ +int ftsoptions; /* options for the ftsopen(3) call */ +int isdeprecated; /* using deprecated syntax */ +int isdepth; /* do directories on post-order visit */ +int isoutput; /* user specified output operator */ +int isxargs; /* don't permit xargs delimiting chars */ + +int main __P((int, char **)); +static void usage __P((void)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + char **p, **start; + int ch; + + (void)time(&now); /* initialize the time-of-day */ + + /* array to hold dir list. at most (argc - 1) elements. */ + p = start = alloca(argc * sizeof (char *)); + + ftsoptions = FTS_NOSTAT | FTS_PHYSICAL; + while ((ch = getopt(argc, argv, "HLPXdf:x")) != EOF) + switch(ch) { + case 'H': + ftsoptions |= FTS_COMFOLLOW; +#if 0 /* XXX necessary? */ + ftsoptions &= ~FTS_LOGICAL; +#endif + break; + case 'L': + ftsoptions &= ~FTS_COMFOLLOW; + ftsoptions |= FTS_LOGICAL; + break; + case 'P': + ftsoptions &= ~(FTS_COMFOLLOW|FTS_LOGICAL); + ftsoptions |= FTS_PHYSICAL; + break; + case 'X': + isxargs = 1; + break; + case 'd': + isdepth = 1; + break; + case 'f': + *p++ = optarg; + break; + case 'h': + ftsoptions &= ~FTS_PHYSICAL; + ftsoptions |= FTS_LOGICAL; + break; + case 'x': + ftsoptions |= FTS_XDEV; + break; + case '?': + default: + break; + } + + argc -= optind; + argv += optind; + + /* + * Find first option to delimit the file list. The first argument + * that starts with a -, or is a ! or a ( must be interpreted as a + * part of the find expression, according to POSIX .2. + */ + for (; *argv != NULL; *p++ = *argv++) { + if (argv[0][0] == '-') + break; + if ((argv[0][0] == '!' || argv[0][0] == '(') && + argv[0][1] == '\0') + break; + } + + if (p == start) + usage(); + *p = NULL; + + if ((dotfd = open(".", O_RDONLY, 0)) < 0) + err(1, "."); + + exit(find_execute(find_formplan(argv), start)); +} + +static void +usage() +{ + (void)fprintf(stderr, +"usage: find [-H | -L | -P] [-Xdhx] [-f file] [file ...] [expression]\n"); + exit(1); +} diff --git a/find/misc.c b/find/misc.c new file mode 100644 index 0000000..cf6a85b --- /dev/null +++ b/find/misc.c @@ -0,0 +1,135 @@ +/* $NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $ */ + +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Cimarron D. Taylor of the University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)misc.c 8.2 (Berkeley) 4/1/94"; +#else +__RCSID("$NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "find.h" + +/* + * brace_subst -- + * Replace occurrences of {} in orig with path, and place it in a malloced + * area of memory set in store. + */ +void +brace_subst(orig, store, path, len) + char *orig, **store, *path; + int len; +{ + int plen; + char ch, *p; + + plen = strlen(path); + for (p = *store; (ch = *orig) != '\0'; ++orig) + if (ch == '{' && orig[1] == '}') { + while ((p - *store) + plen > len) + if (!(*store = realloc(*store, len *= 2))) + err(1, "realloc"); + memmove(p, path, plen); + p += plen; + ++orig; + } else + *p++ = ch; + *p = '\0'; +} + +/* + * queryuser -- + * print a message to standard error and then read input from standard + * input. If the input is 'y' then 1 is returned. + */ +int +queryuser(argv) + char **argv; +{ + int ch, first, nl; + + (void)fprintf(stderr, "\"%s", *argv); + while (*++argv) + (void)fprintf(stderr, " %s", *argv); + (void)fprintf(stderr, "\"? "); + (void)fflush(stderr); + + first = ch = getchar(); + for (nl = 0;;) { + if (ch == '\n') { + nl = 1; + break; + } + if (ch == EOF) + break; + ch = getchar(); + } + + if (!nl) { + (void)fprintf(stderr, "\n"); + (void)fflush(stderr); + } + return (first == 'y'); +} + +/* + * emalloc -- + * malloc with error checking. + */ +void * +emalloc(len) + u_int len; +{ + void *p; + + if ((p = malloc(len)) == NULL) + err(1, "malloc"); + return (p); +} diff --git a/find/operator.c b/find/operator.c new file mode 100644 index 0000000..128a785 --- /dev/null +++ b/find/operator.c @@ -0,0 +1,279 @@ +/* $NetBSD: operator.c,v 1.6 1998/02/21 22:47:21 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Cimarron D. Taylor of the University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)operator.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: operator.c,v 1.6 1998/02/21 22:47:21 christos Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include + +#include "find.h" + +static PLAN *yanknode __P((PLAN **)); +static PLAN *yankexpr __P((PLAN **)); + +/* + * yanknode -- + * destructively removes the top from the plan + */ +static PLAN * +yanknode(planp) + PLAN **planp; /* pointer to top of plan (modified) */ +{ + PLAN *node; /* top node removed from the plan */ + + if ((node = (*planp)) == NULL) + return (NULL); + (*planp) = (*planp)->next; + node->next = NULL; + return (node); +} + +/* + * yankexpr -- + * Removes one expression from the plan. This is used mainly by + * paren_squish. In comments below, an expression is either a + * simple node or a N_EXPR node containing a list of simple nodes. + */ +static PLAN * +yankexpr(planp) + PLAN **planp; /* pointer to top of plan (modified) */ +{ + PLAN *next; /* temp node holding subexpression results */ + PLAN *node; /* pointer to returned node or expression */ + PLAN *tail; /* pointer to tail of subplan */ + PLAN *subplan; /* pointer to head of ( ) expression */ + + /* first pull the top node from the plan */ + if ((node = yanknode(planp)) == NULL) + return (NULL); + + /* + * If the node is an '(' then we recursively slurp up expressions + * until we find its associated ')'. If it's a closing paren we + * just return it and unwind our recursion; all other nodes are + * complete expressions, so just return them. + */ + if (node->type == N_OPENPAREN) + for (tail = subplan = NULL;;) { + if ((next = yankexpr(planp)) == NULL) + err(1, "(: missing closing ')'"); + /* + * If we find a closing ')' we store the collected + * subplan in our '(' node and convert the node to + * a N_EXPR. The ')' we found is ignored. Otherwise, + * we just continue to add whatever we get to our + * subplan. + */ + if (next->type == N_CLOSEPAREN) { + if (subplan == NULL) + errx(1, "(): empty inner expression"); + node->p_data[0] = subplan; + node->type = N_EXPR; + node->eval = f_expr; + break; + } else { + if (subplan == NULL) + tail = subplan = next; + else { + tail->next = next; + tail = next; + } + tail->next = NULL; + } + } + return (node); +} + +/* + * paren_squish -- + * replaces "parentheisized" plans in our search plan with "expr" nodes. + */ +PLAN * +paren_squish(plan) + PLAN *plan; /* plan with ( ) nodes */ +{ + PLAN *expr; /* pointer to next expression */ + PLAN *tail; /* pointer to tail of result plan */ + PLAN *result; /* pointer to head of result plan */ + + result = tail = NULL; + + /* + * the basic idea is to have yankexpr do all our work and just + * collect it's results together. + */ + while ((expr = yankexpr(&plan)) != NULL) { + /* + * if we find an unclaimed ')' it means there is a missing + * '(' someplace. + */ + if (expr->type == N_CLOSEPAREN) + errx(1, "): no beginning '('"); + + /* add the expression to our result plan */ + if (result == NULL) + tail = result = expr; + else { + tail->next = expr; + tail = expr; + } + tail->next = NULL; + } + return (result); +} + +/* + * not_squish -- + * compresses "!" expressions in our search plan. + */ +PLAN * +not_squish(plan) + PLAN *plan; /* plan to process */ +{ + PLAN *next; /* next node being processed */ + PLAN *node; /* temporary node used in N_NOT processing */ + PLAN *tail; /* pointer to tail of result plan */ + PLAN *result; /* pointer to head of result plan */ + + tail = result = next = NULL; + + while ((next = yanknode(&plan)) != NULL) { + /* + * if we encounter a ( expression ) then look for nots in + * the expr subplan. + */ + if (next->type == N_EXPR) + next->p_data[0] = not_squish(next->p_data[0]); + + /* + * if we encounter a not, then snag the next node and place + * it in the not's subplan. As an optimization we compress + * several not's to zero or one not. + */ + if (next->type == N_NOT) { + int notlevel = 1; + + node = yanknode(&plan); + while (node->type == N_NOT) { + ++notlevel; + node = yanknode(&plan); + } + if (node == NULL) + errx(1, "!: no following expression"); + if (node->type == N_OR) + errx(1, "!: nothing between ! and -o"); + if (notlevel % 2 != 1) + next = node; + else + next->p_data[0] = node; + } + + /* add the node to our result plan */ + if (result == NULL) + tail = result = next; + else { + tail->next = next; + tail = next; + } + tail->next = NULL; + } + return (result); +} + +/* + * or_squish -- + * compresses -o expressions in our search plan. + */ +PLAN * +or_squish(plan) + PLAN *plan; /* plan with ors to be squished */ +{ + PLAN *next; /* next node being processed */ + PLAN *tail; /* pointer to tail of result plan */ + PLAN *result; /* pointer to head of result plan */ + + tail = result = next = NULL; + + while ((next = yanknode(&plan)) != NULL) { + /* + * if we encounter a ( expression ) then look for or's in + * the expr subplan. + */ + if (next->type == N_EXPR) + next->p_data[0] = or_squish(next->p_data[0]); + + /* if we encounter a not then look for not's in the subplan */ + if (next->type == N_NOT) + next->p_data[0] = or_squish(next->p_data[0]); + + /* + * if we encounter an or, then place our collected plan in the + * or's first subplan and then recursively collect the + * remaining stuff into the second subplan and return the or. + */ + if (next->type == N_OR) { + if (result == NULL) + errx(1, "-o: no expression before -o"); + next->p_data[0] = result; + next->p_data[1] = or_squish(plan); + if (next->p_data[1] == NULL) + errx(1, "-o: no expression after -o"); + return (next); + } + + /* add the node to our result plan */ + if (result == NULL) + tail = result = next; + else { + tail->next = next; + tail = next; + } + tail->next = NULL; + } + return (result); +} diff --git a/find/option.c b/find/option.c new file mode 100644 index 0000000..f531dab --- /dev/null +++ b/find/option.c @@ -0,0 +1,144 @@ +/* $NetBSD: option.c,v 1.9 1998/02/21 22:47:21 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Cimarron D. Taylor of the University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)option.c 8.2 (Berkeley) 4/16/94"; +#else +__RCSID("$NetBSD: option.c,v 1.9 1998/02/21 22:47:21 christos Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include +#include + +#include "find.h" + +int typecompare __P((const void *, const void *)); +static OPTION *option __P((char *)); + +/* NB: the following table must be sorted lexically. */ +static OPTION const options[] = { + { "!", N_NOT, c_not, 0 }, + { "(", N_OPENPAREN, c_openparen, 0 }, + { ")", N_CLOSEPAREN, c_closeparen, 0 }, + { "-a", N_AND, c_null, 0 }, + { "-and", N_AND, c_null, 0 }, + { "-atime", N_ATIME, c_atime, 1 }, + { "-ctime", N_CTIME, c_ctime, 1 }, + { "-depth", N_DEPTH, c_depth, 0 }, + { "-exec", N_EXEC, c_exec, 1 }, + { "-follow", N_FOLLOW, c_follow, 0 }, + { "-fstype", N_FSTYPE, c_fstype, 1 }, + { "-group", N_GROUP, c_group, 1 }, + { "-inum", N_INUM, c_inum, 1 }, + { "-links", N_LINKS, c_links, 1 }, + { "-ls", N_LS, c_ls, 0 }, + { "-mtime", N_MTIME, c_mtime, 1 }, + { "-name", N_NAME, c_name, 1 }, + { "-newer", N_NEWER, c_newer, 1 }, + { "-nogroup", N_NOGROUP, c_nogroup, 0 }, + { "-nouser", N_NOUSER, c_nouser, 0 }, + { "-o", N_OR, c_or, 0 }, + { "-ok", N_OK, c_exec, 1 }, + { "-or", N_OR, c_or, 0 }, + { "-path", N_PATH, c_path, 1 }, + { "-perm", N_PERM, c_perm, 1 }, + { "-print", N_PRINT, c_print, 0 }, + { "-print0", N_PRINT0, c_print0, 0 }, + { "-prune", N_PRUNE, c_prune, 0 }, + { "-size", N_SIZE, c_size, 1 }, + { "-type", N_TYPE, c_type, 1 }, + { "-user", N_USER, c_user, 1 }, + { "-xdev", N_XDEV, c_xdev, 0 } +}; + +/* + * find_create -- + * create a node corresponding to a command line argument. + * + * TODO: + * add create/process function pointers to node, so we can skip + * this switch stuff. + */ +PLAN * +find_create(argvp) + char ***argvp; +{ + OPTION *p; + PLAN *new; + char **argv; + + argv = *argvp; + + if ((p = option(*argv)) == NULL) + errx(1, "%s: unknown option", *argv); + ++argv; + if (p->arg && !*argv) + errx(1, "%s: requires additional arguments", *--argv); + + new = (p->create)(&argv, p->token == N_OK); + + *argvp = argv; + return (new); +} + +static OPTION * +option(name) + char *name; +{ + OPTION tmp; + + tmp.name = name; + return ((OPTION *)bsearch(&tmp, options, + sizeof(options)/sizeof(OPTION), sizeof(OPTION), typecompare)); +} + +int +typecompare(a, b) + const void *a, *b; +{ + return (strcmp(((OPTION *)a)->name, ((OPTION *)b)->name)); +} diff --git a/getopt/Makefile b/getopt/Makefile new file mode 100644 index 0000000..8a99a0c --- /dev/null +++ b/getopt/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = getopt + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = getopt.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble getopt.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/getopt/Makefile.postamble b/getopt/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/getopt/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/getopt/Makefile.preamble b/getopt/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/getopt/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/getopt/PB.project b/getopt/PB.project new file mode 100644 index 0000000..b33ada1 --- /dev/null +++ b/getopt/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (getopt.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, getopt.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = getopt; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/getopt/getopt.1 b/getopt/getopt.1 new file mode 100644 index 0000000..410f61b --- /dev/null +++ b/getopt/getopt.1 @@ -0,0 +1,121 @@ +.\" $NetBSD: getopt.1,v 1.8 1997/10/19 02:16:57 lukem Exp $ +.Dd June 21, 1993 +.Dt GETOPT 1 +.Os +.Sh NAME +.Nm getopt +.Nd parse command options +.Sh SYNOPSIS +.Li args=\`getopt optstring $*\` +.Pp +.Li set \-\- \`getopt optstring $*\` +.Sh DESCRIPTION +.Nm +is used to break up options in command lines for easy parsing by +shell procedures, and to check for legal options. +.Op Optstring +is a string of recognized option letters (see +.Xr getopt 3 +); +if a letter is followed by a colon, the option +is expected to have an argument which may or may not be +separated from it by white space. +The special option +.Dq \-\- +is used to delimit the end of the options. +.Nm +will place +.Dq \-\- +in the arguments at the end of the options, +or recognize it if used explicitly. +The shell arguments +(\fB$1 $2\fR ...) are reset so that each option is +preceded by a +.Dq \- +and in its own shell argument; +each option argument is also in its own shell argument. +.Sh EXAMPLE +The following code fragment shows how one might process the arguments +for a command that can take the options +.Op a +and +.Op b , +and the option +.Op o , +which requires an argument. +.Pp +.Bd -literal -offset indent +args=\`getopt abo: $*\` +if test $? != 0 +then + echo 'Usage: ...' + exit 2 +fi +set \-\- $args +for i +do + case "$i" + in + \-a|\-b) + flag=$i; shift;; + \-o) + oarg=$2; shift; shift;; + \-\-) + shift; break;; + esac +done +.Ed +.Pp +This code will accept any of the following as equivalent: +.Pp +.Bd -literal -offset indent +cmd \-aoarg file file +cmd \-a \-o arg file file +cmd \-oarg -a file file +cmd \-a \-oarg \-\- file file +.Ed +.Pp +.St -p1003.2 +mandates that the +.Xr sh 1 +set command return the value of 0 for the exit status. Therefore, +the exit status of the +.Nm +command is lost when +.Nm +and the +.Xr sh 1 +set command are used on the same line. The example given +is one way to detect errors found by +.Nm "" . +.Sh SEE ALSO +.Xr sh 1 , +.Xr getopt 3 +.Sh DIAGNOSTICS +.Nm +prints an error message on the standard error output when it +encounters an option letter not included in +.Op optstring . +.Sh HISTORY +Written by Henry Spencer, working from a Bell Labs manual page. +Behavior believed identical to the Bell version. +.Sh BUGS +Whatever +.Xr getopt 3 +has. +.Pp +Arguments containing white space or embedded shell metacharacters +generally will not survive intact; this looks easy to fix but isn't. +.Pp +The error message for an invalid option is identified as coming +from +.Nm +rather than from the shell procedure containing the invocation +of +.Nm "" ; +this again is hard to fix. +.Pp +The precise best way to use the +.Ic set +command to set the arguments without disrupting the value(s) of +shell options varies from one shell version to another. diff --git a/getopt/getopt.c b/getopt/getopt.c new file mode 100644 index 0000000..ca485b3 --- /dev/null +++ b/getopt/getopt.c @@ -0,0 +1,40 @@ +/* $NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $ */ + +#include +#ifndef lint +__RCSID("$NetBSD: getopt.c,v 1.5 1998/02/03 03:44:22 perry Exp $"); +#endif /* not lint */ + +#include +#include +#include + +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int c; + int status = 0; + + optind = 2; /* Past the program name and the option letters. */ + while ((c = getopt(argc, argv, argv[1])) != -1) + switch (c) { + case '?': + status = 1; /* getopt routine gave message */ + break; + default: + if (optarg != NULL) + printf(" -%c %s", c, optarg); + else + printf(" -%c", c); + break; + } + printf(" --"); + for (; optind < argc; optind++) + printf(" %s", argv[optind]); + printf("\n"); + exit(status); +} diff --git a/hostname/Makefile b/hostname/Makefile new file mode 100644 index 0000000..f1ded63 --- /dev/null +++ b/hostname/Makefile @@ -0,0 +1,49 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = hostname + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = hostname.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble hostname.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +NEXTSTEP_PB_CFLAGS = -DKERNEL_PRIVATE + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/hostname/Makefile.postamble b/hostname/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/hostname/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/hostname/Makefile.preamble b/hostname/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/hostname/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/hostname/PB.project b/hostname/PB.project new file mode 100644 index 0000000..e120a56 --- /dev/null +++ b/hostname/PB.project @@ -0,0 +1,28 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (hostname.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, hostname.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_COMPILEROPTIONS = "-DKERNEL_PRIVATE"; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = hostname; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/hostname/hostname.1 b/hostname/hostname.1 new file mode 100644 index 0000000..c64e9f0 --- /dev/null +++ b/hostname/hostname.1 @@ -0,0 +1,69 @@ +.\" $NetBSD: hostname.1,v 1.13 1997/10/20 08:52:03 enami Exp $ +.\" +.\" Copyright (c) 1983, 1988, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)hostname.1 8.2 (Berkeley) 4/28/95 +.\" +.Dd April 28, 1995 +.Dt HOSTNAME 1 +.Os BSD 4.2 +.Sh NAME +.Nm hostname +.Nd set or print name of current host system +.Sh SYNOPSIS +.Nm +.Op Fl s +.Op Ar name-of-host +.Sh DESCRIPTION +.Nm +prints the name of the current host. The super-user can +set the host name by supplying an argument; this is usually done in the +network initialization script +.Pa /etc/netstart , +normally run at boot +time. +.Pp +Options: +.Bl -tag -width flag +.It Fl s +Trims off any domain information from the printed +name. +.El +.Sh SEE ALSO +.Xr domainname 1 , +.Xr gethostname 3 , +.Xr sethostname 3 +.Sh HISTORY +The +.Nm +utility appeared in +.Bx 4.2 . diff --git a/hostname/hostname.c b/hostname/hostname.c new file mode 100644 index 0000000..e78fe5c --- /dev/null +++ b/hostname/hostname.c @@ -0,0 +1,107 @@ +/* $NetBSD: hostname.c,v 1.13 1998/07/28 05:31:24 mycroft Exp $ */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)hostname.c 8.2 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: hostname.c,v 1.13 1998/07/28 05:31:24 mycroft Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include + +void usage __P((void)); +int main __P((int, char *[])); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int ch, sflag; + char *p, hostname[MAXHOSTNAMELEN + 1]; + + sflag = 0; + while ((ch = getopt(argc, argv, "s")) != -1) + switch (ch) { + case 's': + sflag = 1; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc > 1) + usage(); + + if (*argv) { + if (sethostname(*argv, strlen(*argv))) + err(1, "sethostname"); + } else { + if (gethostname(hostname, sizeof(hostname))) + err(1, "gethostname"); + hostname[sizeof(hostname) - 1] = '\0'; + if (sflag && (p = strchr(hostname, '.'))) + *p = '\0'; + (void)printf("%s\n", hostname); + } + exit(0); + /* NOTREACHED */ +} + +void +usage() +{ + + (void)fprintf(stderr, "usage: hostname [-s] [name-of-host]\n"); + exit(1); + /* NOTREACHED */ +} diff --git a/id/Makefile b/id/Makefile new file mode 100644 index 0000000..0bbc53f --- /dev/null +++ b/id/Makefile @@ -0,0 +1,50 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = id + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = id.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble groups.1\ + id.1 whoami.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +NEXTSTEP_PB_CFLAGS = -Wno-error + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/id/Makefile.postamble b/id/Makefile.postamble new file mode 100644 index 0000000..e161269 --- /dev/null +++ b/id/Makefile.postamble @@ -0,0 +1,5 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common + +after_install:: + $(LINKPRODUCT) $(DSTROOT)$(INSTALLDIR)/groups + $(LINKPRODUCT) $(DSTROOT)$(INSTALLDIR)/whoami diff --git a/id/Makefile.preamble b/id/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/id/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/id/PB.project b/id/PB.project new file mode 100644 index 0000000..ad50e39 --- /dev/null +++ b/id/PB.project @@ -0,0 +1,28 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (id.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, groups.1, id.1, whoami.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_COMPILEROPTIONS = "-Wno-error"; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = id; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/id/groups.1 b/id/groups.1 new file mode 100644 index 0000000..02a90e9 --- /dev/null +++ b/id/groups.1 @@ -0,0 +1,66 @@ +.\" $NetBSD: groups.1,v 1.6 1998/04/28 07:19:29 fair Exp $ +.\" +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)groups.1 8.1 (Berkeley) 6/6/93 +.\" $NetBSD: groups.1,v 1.6 1998/04/28 07:19:29 fair Exp $ +.\" +.Dd June 6, 1993 +.Dt GROUPS 1 +.Os BSD 3 +.Sh NAME +.Nm groups +.Nd show group memberships +.Sh SYNOPSIS +.Nm +.Op Ar user +.Sh DESCRIPTION +The +.Nm +utility has been obsoleted by the +.Xr id 1 +utility, and is equivalent to +.Dq Nm id Fl Gn Op Ar user . +The command +.Dq Nm id Fl p +is suggested for normal interactive use. +.Pp +The +.Nm +utility displays the groups to which you (or the optionally specified user) +belong. +.Pp +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Sh SEE ALSO +.Xr id 1 diff --git a/id/id.1 b/id/id.1 new file mode 100644 index 0000000..b4b2bc7 --- /dev/null +++ b/id/id.1 @@ -0,0 +1,141 @@ +.\" $NetBSD: id.1,v 1.7 1997/10/19 02:45:47 lukem Exp $ +.\" +.\" Copyright (c) 1991, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)id.1 8.2 (Berkeley) 5/5/94 +.\" +.Dd May 5, 1994 +.Dt ID 1 +.Os BSD 4.4 +.Sh NAME +.Nm id +.Nd return user identity +.Sh SYNOPSIS +.Nm +.Op Ar user +.Nm "" +.Fl G Op Fl n +.Op Ar user +.Nm "" +.Fl g Op Fl nr +.Op Ar user +.Nm "" +.Fl p +.Nm "" +.Fl u Op Fl nr +.Op Ar user +.Sh DESCRIPTION +The +.Nm +utility displays the user and group names and numeric IDs, of the +calling process, to the standard output. +If the real and effective IDs are different, both are displayed, +otherwise only the real ID is displayed. +.Pp +If a +.Ar user +(login name or user ID) +is specified, the user and group IDs of that user are displayed. +In this case, the real and effective IDs are assumed to be the same. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl G +Display the different group IDs (effective, real and supplementary) +as white-space separated numbers, in no particular order. +.It Fl g +Display the effective group ID as a number. +.It Fl n +Display the name of the user or group ID for the +.Fl G , +.Fl g +and +.Fl u +options instead of the number. +If any of the ID numbers cannot be mapped into names, the number will be +displayed as usual. +.It Fl p +Make the output human-readable. +If the user name returned by +.Xr getlogin 2 +is different from the login name referenced by the user ID, the name +returned by +.Xr getlogin 2 +is displayed, preceded by the keyword ``login''. +The user ID as a name is displayed, preceded by the keyword ``uid''. +If the effective user ID is different from the real user ID, the real user +ID is displayed as a name, preceded by the keyword ``euid''. +If the effective group ID is different from the real group ID, the real group +ID is displayed as a name, preceded by the keyword ``rgid''. +The list of groups to which the user belongs is then displayed as names, +preceded by the keyword ``groups''. +Each display is on a separate line. +.It Fl r +Display the real ID for the +.Fl g +and +.Fl u +options instead of the effective ID. +.It Fl u +Display the effective user ID as a number. +.El +.Pp +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Sh SEE ALSO +.Xr who 1 +.Sh STANDARDS +The +.Nm +function is expected to conform to +.St -p1003.2 . +.Sh HISTORY +The +historic +.Xr groups 1 +command is equivalent to +.Dq Nm id Fl Gn Op Ar user . +.Pp +The +historic +.Xr whoami 1 +command is equivalent to +.Dq Nm id Fl un . +.Pp +The +.Nm +command first appeared in +.Bx 4.4 . diff --git a/id/id.c b/id/id.c new file mode 100644 index 0000000..b8732a0 --- /dev/null +++ b/id/id.c @@ -0,0 +1,345 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)id.c 8.3 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: id.c,v 1.10 1998/08/25 20:59:37 ross Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +void current __P((void)); +void pretty __P((struct passwd *)); +int main __P((int, char **)); +void group __P((struct passwd *, int)); +void usage __P((void)); +void user __P((struct passwd *)); +struct passwd * + who __P((char *)); + +#ifdef __APPLE__ +extern char *__progname; +#endif + +int +main(argc, argv) + int argc; + char *argv[]; +{ + struct group *gr; + struct passwd *pw; + int ch, id; + int Gflag, gflag, nflag, pflag, rflag, uflag; + + Gflag = gflag = nflag = pflag = rflag = uflag = 0; + + if (!strcmp(__progname, "groups")) { + Gflag = 1; + nflag = 1; + } + else if (!strcmp(__progname, "whoami")) { + uflag = 1; + nflag = 1; + } + + while ((ch = getopt(argc, argv, "Ggnpru")) != -1) + switch(ch) { + case 'G': + Gflag = 1; + break; + case 'g': + gflag = 1; + break; + case 'n': + nflag = 1; + break; + case 'p': + pflag = 1; + break; + case 'r': + rflag = 1; + break; + case 'u': + uflag = 1; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + switch(Gflag + gflag + pflag + uflag) { + case 1: + break; + case 0: + if (!nflag && !rflag) + break; + /* FALLTHROUGH */ + default: + usage(); + } + + pw = *argv ? who(*argv) : NULL; + + if (gflag) { + id = pw ? pw->pw_gid : rflag ? getgid() : getegid(); + if (nflag && (gr = getgrgid(id))) + (void)printf("%s\n", gr->gr_name); + else + (void)printf("%u\n", id); + exit(0); + } + + if (uflag) { + id = pw ? pw->pw_uid : rflag ? getuid() : geteuid(); + if (nflag && (pw = getpwuid(id))) + (void)printf("%s\n", pw->pw_name); + else + (void)printf("%u\n", id); + exit(0); + } + + if (Gflag) { + group(pw, nflag); + exit(0); + } + + if (pflag) { + pretty(pw); + exit(0); + } + + if (pw) + user(pw); + else + current(); + exit(0); +} + +void +pretty(pw) + struct passwd *pw; +{ + struct group *gr; + u_int eid, rid; + char *login; + + if (pw) { + (void)printf("uid\t%s\n", pw->pw_name); + (void)printf("groups\t"); + group(pw, 1); + } else { + if ((login = getlogin()) == NULL) + err(1, "getlogin"); + + pw = getpwuid(rid = getuid()); + if (pw == NULL || strcmp(login, pw->pw_name)) + (void)printf("login\t%s\n", login); + if (pw) + (void)printf("uid\t%s\n", pw->pw_name); + else + (void)printf("uid\t%u\n", rid); + + if ((eid = geteuid()) != rid) { + if ((pw = getpwuid(eid)) != NULL) + (void)printf("euid\t%s", pw->pw_name); + else + (void)printf("euid\t%u", eid); + } + if ((rid = getgid()) != (eid = getegid())) { + if ((gr = getgrgid(rid)) != NULL) + (void)printf("rgid\t%s\n", gr->gr_name); + else + (void)printf("rgid\t%u\n", rid); + } + (void)printf("groups\t"); + group(NULL, 1); + } +} + +void +current() +{ + struct group *gr; + struct passwd *pw; + int cnt, id, eid, lastid, ngroups; + gid_t groups[NGROUPS]; + char *fmt; + + id = getuid(); + (void)printf("uid=%u", id); + if ((pw = getpwuid(id)) != NULL) + (void)printf("(%s)", pw->pw_name); + if ((eid = geteuid()) != id) { + (void)printf(" euid=%u", eid); + if ((pw = getpwuid(eid)) != NULL) + (void)printf("(%s)", pw->pw_name); + } + id = getgid(); + (void)printf(" gid=%u", id); + if ((gr = getgrgid(id)) != NULL) + (void)printf("(%s)", gr->gr_name); + if ((eid = getegid()) != id) { + (void)printf(" egid=%u", eid); + if ((gr = getgrgid(eid)) != NULL) + (void)printf("(%s)", gr->gr_name); + } + if ((ngroups = getgroups(NGROUPS, groups)) != NULL) { + for (fmt = " groups=%u", lastid = -1, cnt = 0; cnt < ngroups; + fmt = ", %u", lastid = id) { + id = groups[cnt++]; + if (lastid == id) + continue; + (void)printf(fmt, id); + if ((gr = getgrgid(id)) != NULL) + (void)printf("(%s)", gr->gr_name); + } + } + (void)printf("\n"); +} + +void +user(pw) + struct passwd *pw; +{ + struct group *gr; + char *fmt; + int cnt, id, lastid, ngroups, groups[NGROUPS + 1]; + + id = pw->pw_uid; + (void)printf("uid=%u(%s)", id, pw->pw_name); + (void)printf(" gid=%u", pw->pw_gid); + if ((gr = getgrgid(pw->pw_gid)) != NULL) + (void)printf("(%s)", gr->gr_name); + ngroups = NGROUPS + 1; + (void) getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); + fmt = " groups=%u"; + for (lastid = -1, cnt = 0; cnt < ngroups; ++cnt) { + if (lastid == (id = groups[cnt])) + continue; + (void)printf(fmt, id); + fmt = " %u"; + if ((gr = getgrgid(id)) != NULL) + (void)printf("(%s)", gr->gr_name); + lastid = id; + } + (void)printf("\n"); +} + +void +group(pw, nflag) + struct passwd *pw; + int nflag; +{ + struct group *gr; + int cnt, id, lastid, ngroups; + gid_t groups[NGROUPS + 1]; + char *fmt; + + if (pw) { + ngroups = NGROUPS + 1; + (void) getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); + } else { + groups[0] = getgid(); + ngroups = getgroups(NGROUPS, groups + 1) + 1; + } + fmt = nflag ? "%s" : "%u"; + for (lastid = -1, cnt = 0; cnt < ngroups; ++cnt) { + if (lastid == (id = groups[cnt])) + continue; + if (nflag) { + if ((gr = getgrgid(id)) != NULL) + (void)printf(fmt, gr->gr_name); + else + (void)printf(*fmt == ' ' ? " %u" : "%u", + id); + fmt = " %s"; + } else { + (void)printf(fmt, id); + fmt = " %u"; + } + lastid = id; + } + (void)printf("\n"); +} + +struct passwd * +who(u) + char *u; +{ + struct passwd *pw; + long id; + char *ep; + + /* + * Translate user argument into a pw pointer. First, try to + * get it as specified. If that fails, try it as a number. + */ + if ((pw = getpwnam(u)) != NULL) + return(pw); + id = strtol(u, &ep, 10); + if (*u && !*ep && (pw = getpwuid(id))) + return(pw); + errx(1, "%s: No such user", u); + /* NOTREACHED */ + return (NULL); +} + +void +usage() +{ + (void)fprintf(stderr, "usage: id [user]\n"); + (void)fprintf(stderr, " id -G [-n] [user]\n"); + (void)fprintf(stderr, " id -g [-nr] [user]\n"); + (void)fprintf(stderr, " id -u [-nr] [user]\n"); + exit(1); +} diff --git a/id/whoami.1 b/id/whoami.1 new file mode 100644 index 0000000..38666fb --- /dev/null +++ b/id/whoami.1 @@ -0,0 +1,64 @@ +.\" $NetBSD: whoami.1,v 1.6 1998/04/28 07:19:29 fair Exp $ +.\" +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)whoami.1 8.1 (Berkeley) 6/6/93 +.\" $NetBSD: whoami.1,v 1.6 1998/04/28 07:19:29 fair Exp $ +.\" +.Dd June 6, 1993 +.Dt WHOAMI 1 +.Os BSD 3 +.Sh NAME +.Nm whoami +.Nd display effective user id +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +utility has been obsoleted by the +.Xr id 1 +utility, and is equivalent to +.Dq Nm id Fl un . +The command +.Dq Nm id Fl p +is suggested for normal interactive use. +.Pp +The +.Nm +utility displays your effective user ID as a name. +.Pp +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Sh SEE ALSO +.Xr id 1 diff --git a/jot/Makefile b/jot/Makefile new file mode 100644 index 0000000..cc14754 --- /dev/null +++ b/jot/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = jot + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = jot.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble jot.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/jot/Makefile.postamble b/jot/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/jot/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/jot/Makefile.preamble b/jot/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/jot/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/jot/PB.project b/jot/PB.project new file mode 100644 index 0000000..9d38f09 --- /dev/null +++ b/jot/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (jot.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, jot.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = jot; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/jot/jot.1 b/jot/jot.1 new file mode 100644 index 0000000..0d13232 --- /dev/null +++ b/jot/jot.1 @@ -0,0 +1,201 @@ +.\" $NetBSD: jot.1,v 1.3 1997/11/01 04:58:39 mycroft Exp $ +.\" +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)jot.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd November 1, 1997 +.Dt JOT 1 +.Os +.Sh NAME +.Nm jot +.Nd print sequential or random data +.Sh SYNOPSIS +.Nm jot +.Op Fl rcn +.Op Fl b Ar word +.Op Fl w Ar word +.Op Fl s Ar string +.Op Fl p Ar precision +.Oo Ar reps +.Oo Ar begin +.Oo Ar end +.Op Ar s +.Oc +.Oc +.Oc +.Sh DESCRIPTION +The +.Nm jot +utility is used to print out increasing, decreasing, random, +or redundant data (usually numbers) one per line. +.Pp +The following options are available: +.Bl -tag -width indent +.It Fl r +Generate random data instead of sequential data, the default. +.It Fl b Ar word +Just print +.Ar word +repetitively. +.It Fl w Ar word +Print +.Ar word +with the generated data appended to it. +Octal, hexadecimal, exponential, ASCII, zero padded, +and right-adjusted representations +are possible by using the appropriate +.Xr printf 3 +conversion specification inside +.Ar word , +in which case the data are inserted rather than appended. +.It Fl c +This is an abbreviation for \fB\-w %c\fP. +.It Fl s Ar string +Print data separated by +.Ar string . +Normally, newlines separate data. +.It Fl n +Do not print the final newline normally appended to the output. +.It Fl p Ar precision +Print only as many digits or characters of the data +as indicated by the integer +.Ar precision . +In the absence of +.Fl p , +the precision is the greater of the precisions of +.Ar begin +and +.Ar end . +The +.Fl p +option is overridden by whatever appears in a +.Xr printf 3 +conversion following +.Fl w . +.El +.Pp +The last four arguments indicate, respectively, +the number of data, the lower bound, the upper bound, +and the step size or, for random data, the seed. +While at least one of them must appear, +any of the other three may be omitted, and +will be considered as such if given as +.Dq - . +Any three of these arguments determines the fourth. +If four are specified and the given and computed values of +.Ar reps +conflict, the lower value is used. +If fewer than three are specified, defaults are assigned +left to right, except for +.Ar s , +which assumes its default unless both +.Ar begin +and +.Ar end +are given. +.Pp +Defaults for the four arguments are, respectively, +100, 1, 100, and 1, except that when random data are requested, +.Ar s +defaults to a seed depending upon the time of day. +.Ar reps +is expected to be an unsigned integer, +and if given as zero is taken to be infinite. +.Ar begin +and +.Ar end +may be given as real numbers or as characters +representing the corresponding value in ASCII. +The last argument must be a real number. +.Pp +Random numbers are obtained through +.Xr random 3 . +The name +.Nm jot +derives in part from +.Nm iota , +a function in APL. +.Sh EXAMPLES +The command: +.Dl "jot 21 \-1 1.00" +prints 21 evenly spaced numbers increasing from \-1 to 1. +.Pp +The command: +.Dl "jot \-c 128 0" +prints the ASCII character set. +.Pp +The command: +.Dl "jot \-w xa%c 26 a" +prints the strings +.Dq xaa +through +.Dq xaz . +.Pp +The command: +.Dl "jot \-r \-c 160 a z | rs \-g 0 8" +prints 20 random 8-letter strings. +.Pp +The command: +.Dl "jot \-b y 0" +is equivalent to +.Xr yes 1 . +.Pp +The command: +.Dl "jot \-w %ds/old/new/ 30 2 \- 5" +prints thirty +.Xr ed 1 +substitution commands applying to lines 2, 7, 12, etc. +.Pp +The command: +.Dl "jot 0 9 \- \-.5" +prints the stuttering sequence 9, 9, 8, 8, 7, etc. +.Pp +The command: +.Dl "jot \-b x 512 > block" +creates a file containing exactly 1024 bytes. +.Pp +The command: +.Dl "expand \-\`jot \-s, \- 10 132 4\`" +sets tabs four spaces apart starting +from column 10 and ending in column 132. +.Pp +The command: +.Dl "grep \`jot \-s """" \-b . 80\`" +prints all lines 80 characters or longer. +.Sh SEE ALSO +.Xr ed 1 , +.Xr expand 1 , +.Xr rs 1 , +.Xr yes 1 , +.Xr printf 3 , +.Xr random 3 diff --git a/jot/jot.c b/jot/jot.c new file mode 100644 index 0000000..92b9f9e --- /dev/null +++ b/jot/jot.c @@ -0,0 +1,399 @@ +/* $NetBSD: jot.c,v 1.4 1997/10/19 03:34:49 lukem Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)jot.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: jot.c,v 1.4 1997/10/19 03:34:49 lukem Exp $"); +#endif /* not lint */ + +/* + * jot - print sequential or random data + * + * Author: John Kunze, Office of Comp. Affairs, UCB + */ + +#include +#include +#include +#include +#include +#include +#include + +#define REPS_DEF 100 +#define BEGIN_DEF 1 +#define ENDER_DEF 100 +#define STEP_DEF 1 + +#define isdefault(s) (strcmp((s), "-") == 0) + +double begin; +double ender; +double s; +long reps; +int randomize; +int infinity; +int boring; +int prec; +int dox; +int chardata; +int nofinalnl; +char sepstring[BUFSIZ] = "\n"; +char format[BUFSIZ]; + +void error __P((char *, char *)); +void getargs __P((int, char *[])); +void getformat __P((void)); +int getprec __P((char *)); +int main __P((int, char **)); +void putdata __P((double, long)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + double xd, yd; + long id; + double *x = &xd; + double *y = &yd; + long *i = &id; + + getargs(argc, argv); + if (randomize) { + *x = (ender - begin) * (ender > begin ? 1 : -1); + srandom((int) s); + for (*i = 1; *i <= reps || infinity; (*i)++) { + *y = (double) random() / INT_MAX; + putdata(*y * *x + begin, reps - *i); + } + } + else + for (*i = 1, *x = begin; *i <= reps || infinity; (*i)++, *x += s) + putdata(*x, reps - *i); + if (!nofinalnl) + putchar('\n'); + exit(0); +} + +void +getargs(ac, av) + int ac; + char *av[]; +{ + unsigned int mask = 0; + int n = 0; + + while (--ac && **++av == '-' && !isdefault(*av)) + switch ((*av)[1]) { + case 'r': + randomize = 1; + break; + case 'c': + chardata = 1; + break; + case 'n': + nofinalnl = 1; + break; + case 'b': + boring = 1; + case 'w': + if ((*av)[2]) + strcpy(format, *av + 2); + else if (!--ac) + error("Need context word after -w or -b", ""); + else + strcpy(format, *++av); + break; + case 's': + if ((*av)[2]) + strcpy(sepstring, *av + 2); + else if (!--ac) + error("Need string after -s", ""); + else + strcpy(sepstring, *++av); + break; + case 'p': + if ((*av)[2]) + prec = atoi(*av + 2); + else if (!--ac) + error("Need number after -p", ""); + else + prec = atoi(*++av); + if (prec <= 0) + error("Bad precision value", ""); + break; + default: + error("Unknown option %s", *av); + } + + switch (ac) { /* examine args right to left, falling thru cases */ + case 4: + if (!isdefault(av[3])) { + if (!sscanf(av[3], "%lf", &s)) + error("Bad s value: %s", av[3]); + mask |= 01; + } + case 3: + if (!isdefault(av[2])) { + if (!sscanf(av[2], "%lf", &ender)) + ender = av[2][strlen(av[2])-1]; + mask |= 02; + if (!prec) + n = getprec(av[2]); + } + case 2: + if (!isdefault(av[1])) { + if (!sscanf(av[1], "%lf", &begin)) + begin = av[1][strlen(av[1])-1]; + mask |= 04; + if (!prec) + prec = getprec(av[1]); + if (n > prec) /* maximum precision */ + prec = n; + } + case 1: + if (!isdefault(av[0])) { + if (!sscanf(av[0], "%ld", &reps)) + error("Bad reps value: %s", av[0]); + mask |= 010; + } + break; + case 0: + error("jot - print sequential or random data", ""); + default: + error("Too many arguments. What do you mean by %s?", av[4]); + } + getformat(); + while (mask) /* 4 bit mask has 1's where last 4 args were given */ + switch (mask) { /* fill in the 0's by default or computation */ + case 001: + reps = REPS_DEF; + mask = 011; + break; + case 002: + reps = REPS_DEF; + mask = 012; + break; + case 003: + reps = REPS_DEF; + mask = 013; + break; + case 004: + reps = REPS_DEF; + mask = 014; + break; + case 005: + reps = REPS_DEF; + mask = 015; + break; + case 006: + reps = REPS_DEF; + mask = 016; + break; + case 007: + if (randomize) { + reps = REPS_DEF; + mask = 0; + break; + } + if (s == 0.0) { + reps = 0; + mask = 0; + break; + } + reps = (ender - begin + s) / s; + if (reps <= 0) + error("Impossible stepsize", ""); + mask = 0; + break; + case 010: + begin = BEGIN_DEF; + mask = 014; + break; + case 011: + begin = BEGIN_DEF; + mask = 015; + break; + case 012: + s = (randomize ? time(0) : STEP_DEF); + mask = 013; + break; + case 013: + if (randomize) + begin = BEGIN_DEF; + else if (reps == 0) + error("Must specify begin if reps == 0", ""); + begin = ender - reps * s + s; + mask = 0; + break; + case 014: + s = (randomize ? time(0) : STEP_DEF); + mask = 015; + break; + case 015: + if (randomize) + ender = ENDER_DEF; + else + ender = begin + reps * s - s; + mask = 0; + break; + case 016: + if (randomize) + s = time(0); + else if (reps == 0) + error("Infinite sequences cannot be bounded", + ""); + else if (reps == 1) + s = 0.0; + else + s = (ender - begin) / (reps - 1); + mask = 0; + break; + case 017: /* if reps given and implied, */ + if (!randomize && s != 0.0) { + long t = (ender - begin + s) / s; + if (t <= 0) + error("Impossible stepsize", ""); + if (t < reps) /* take lesser */ + reps = t; + } + mask = 0; + break; + default: + error("Bad mask", ""); + } + if (reps == 0) + infinity = 1; +} + +void +putdata(x, notlast) + double x; + long notlast; +{ + long d = x; + long *dp = &d; + + if (boring) /* repeated word */ + printf("%s", format); + else if (dox) /* scalar */ + printf(format, *dp); + else /* real */ + printf(format, x); + if (notlast != 0) + fputs(sepstring, stdout); +} + +void +error(msg, s) + char *msg, *s; +{ + warnx(msg, s); + fprintf(stderr, + "\nusage: jot [ options ] [ reps [ begin [ end [ s ] ] ] ]\n"); + if (strncmp("jot - ", msg, 6) == 0) + fprintf(stderr, "Options:\n\t%s\t%s\t%s\t%s\t%s\t%s\t%s", + "-r random data\n", + "-c character data\n", + "-n no final newline\n", + "-b word repeated word\n", + "-w word context word\n", + "-s string data separator\n", + "-p precision number of characters\n"); + exit(1); +} + +int +getprec(s) + char *s; +{ + char *p; + char *q; + + for (p = s; *p; p++) + if (*p == '.') + break; + if (!*p) + return (0); + for (q = ++p; *p; p++) + if (!isdigit(*p)) + break; + return (p - q); +} + +void +getformat() +{ + char *p; + + if (boring) /* no need to bother */ + return; + for (p = format; *p; p++) /* look for '%' */ + if (*p == '%' && *(p+1) != '%') /* leave %% alone */ + break; + if (!*p && !chardata) + sprintf(p, "%%.%df", prec); + else if (!*p && chardata) { + strcpy(p, "%c"); + dox = 1; + } + else if (!*(p+1)) + strcat(format, "%"); /* cannot end in single '%' */ + else { + while (!isalpha(*p)) + p++; + switch (*p) { + case 'f': case 'e': case 'g': case '%': + break; + case 's': + error("Cannot convert numeric data to strings", ""); + break; + /* case 'd': case 'o': case 'x': case 'D': case 'O': case 'X': + case 'c': case 'u': */ + default: + dox = 1; + break; + } + } +} diff --git a/kill/Makefile b/kill/Makefile new file mode 100644 index 0000000..15b4692 --- /dev/null +++ b/kill/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = kill + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = kill.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble kill.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/kill/Makefile.postamble b/kill/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/kill/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/kill/Makefile.preamble b/kill/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/kill/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/kill/PB.project b/kill/PB.project new file mode 100644 index 0000000..9e03d45 --- /dev/null +++ b/kill/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (kill.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, kill.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = kill; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/kill/kill.1 b/kill/kill.1 new file mode 100644 index 0000000..5ad2a47 --- /dev/null +++ b/kill/kill.1 @@ -0,0 +1,144 @@ +.\" $NetBSD: kill.1,v 1.10 1997/10/20 08:52:10 enami Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)kill.1 8.2 (Berkeley) 4/28/95 +.\" +.Dd April 28, 1995 +.Dt KILL 1 +.Os +.Sh NAME +.Nm kill +.Nd terminate or signal a process +.Sh SYNOPSIS +.Nm +.Op Fl s Ar signal_name +.Ar pid +\&... +.Nm "" +.Fl l +.Op Ar exit_status +.Nm "" +.Fl signal_name +.Ar pid +\&... +.Nm "" +.Fl signal_number +.Ar pid +\&... +.Sh DESCRIPTION +The kill utility sends a signal to the processes specified +by the pid operand(s). +.Pp +Only the super-user may send signals to other users' processes. +.Pp +The options are as follows: +.Pp +.Bl -tag -width Ds +.It Fl s Ar signal_name +A symbolic signal name specifying the signal to be sent instead of the +default +.Dv TERM . +.It Fl l Op Ar exit_status +If no operand is given, list the signal names; otherwise, write +the signal name corresponding to +.Ar exit_status . +.It Fl signal_name +A symbolic signal name specifying the signal to be sent instead of the +default +.Dv TERM . +.It Fl signal_number +A non-negative decimal integer, specifying the signal to be sent instead +of the default +.Dv TERM . +.El +.Pp +The following pids have special meanings: +.Bl -tag -width Ds -compact +.It -1 +If superuser, broadcast the signal to all processes; otherwise broadcast +to all processes belonging to the user. +.El +.Pp +Some of the more commonly used signals: +.Bl -tag -width Ds -compact +.It 1 +HUP (hang up) +.It 2 +INT (interrupt) +.It 3 +QUIT (quit) +.It 6 +ABRT (abort) +.It 9 +KILL (non-catchable, non-ignorable kill) +.It 14 +ALRM (alarm clock) +.It 15 +TERM (software termination signal) +.El +.Pp +.Nm +is a built-in to +.Xr csh 1 ; +it allows job specifiers of the form ``%...'' as arguments +so process id's are not as often used as +.Nm +arguments. +See +.Xr csh 1 +for details. +.Sh SEE ALSO +.Xr csh 1 , +.Xr ps 1 , +.Xr kill 2 , +.Xr sigaction 2 +.Sh STANDARDS +The +.Nm +function is expected to be +.St -p1003.2 +compatible. +.Sh HISTORY +A +.Nm +command appeared in +.At v6 . +.Sh BUGS +A replacement for the command +.Dq Li kill 0 +for +.Xr csh 1 +users should be provided. diff --git a/kill/kill.c b/kill/kill.c new file mode 100644 index 0000000..f78eba3 --- /dev/null +++ b/kill/kill.c @@ -0,0 +1,196 @@ +/* $NetBSD: kill.c,v 1.16 1998/07/28 11:41:49 mycroft Exp $ */ + +/* + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)kill.c 8.4 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: kill.c,v 1.16 1998/07/28 11:41:49 mycroft Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include + +void nosig __P((char *)); +void printsignals __P((FILE *)); +int signame_to_signum __P((char *)); +void usage __P((void)); +int main __P((int, char *[])); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int errors, numsig, pid; + char *ep; + + if (argc < 2) + usage(); + + numsig = SIGTERM; + + argc--, argv++; + if (!strcmp(*argv, "-l")) { + argc--, argv++; + if (argc > 1) + usage(); + if (argc == 1) { + if (!isdigit(**argv)) + usage(); + numsig = strtol(*argv, &ep, 10); + if (*ep) + errx(1, "illegal signal number: %s", *argv); + if (numsig >= 128) + numsig -= 128; + if (numsig <= 0 || numsig >= NSIG) + nosig(*argv); + (void)printf("%s\n", sys_signame[numsig]); + exit(0); + } + printsignals(stdout); + exit(0); + } + + if (!strcmp(*argv, "-s")) { + argc--, argv++; + if (argc < 1) { + warnx("option requires an argument -- s"); + usage(); + } + if (strcmp(*argv, "0")) { + if ((numsig = signame_to_signum(*argv)) < 0) + nosig(*argv); + } else + numsig = 0; + argc--, argv++; + } else if (**argv == '-') { + ++*argv; + if (isalpha(**argv)) { + if ((numsig = signame_to_signum(*argv)) < 0) + nosig(*argv); + } else if (isdigit(**argv)) { + numsig = strtol(*argv, &ep, 10); + if (!*argv || *ep) + errx(1, "illegal signal number: %s", *argv); + if (numsig < 0 || numsig >= NSIG) + nosig(*argv); + } else + nosig(*argv); + argc--, argv++; + } + + if (argc == 0) + usage(); + + for (errors = 0; argc; argc--, argv++) { + pid = strtol(*argv, &ep, 10); + if (!**argv || *ep) { + warnx("illegal process id: %s", *argv); + errors = 1; + } else if (kill(pid, numsig) == -1) { + warn("%s", *argv); + errors = 1; + } + } + + exit(errors); + /* NOTREACHED */ +} + +int +signame_to_signum(sig) + char *sig; +{ + int n; + + if (!strncasecmp(sig, "sig", 3)) + sig += 3; + for (n = 1; n < NSIG; n++) { + if (!strcasecmp(sys_signame[n], sig)) + return (n); + } + return (-1); +} + +void +nosig(name) + char *name; +{ + + warnx("unknown signal %s; valid signals:", name); + printsignals(stderr); + exit(1); + /* NOTREACHED */ +} + +void +printsignals(fp) + FILE *fp; +{ + int n; + + for (n = 1; n < NSIG; n++) { + (void)fprintf(fp, "%s", sys_signame[n]); + if (n == (NSIG / 2) || n == (NSIG - 1)) + (void)fprintf(fp, "\n"); + else + (void)fprintf(fp, " "); + } +} + +void +usage() +{ + + (void)fprintf(stderr, "usage: kill [-s signal_name] pid ...\n"); + (void)fprintf(stderr, " kill -l [exit_status]\n"); + (void)fprintf(stderr, " kill -signal_name pid ...\n"); + (void)fprintf(stderr, " kill -signal_number pid ...\n"); + exit(1); + /* NOTREACHED */ +} diff --git a/lastcomm/Makefile b/lastcomm/Makefile new file mode 100644 index 0000000..18e424b --- /dev/null +++ b/lastcomm/Makefile @@ -0,0 +1,50 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = lastcomm + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = pathnames.h + +CFILES = lastcomm.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble lastcomm.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/lastcomm/Makefile.postamble b/lastcomm/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/lastcomm/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/lastcomm/Makefile.preamble b/lastcomm/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/lastcomm/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/lastcomm/PB.project b/lastcomm/PB.project new file mode 100644 index 0000000..c476955 --- /dev/null +++ b/lastcomm/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (pathnames.h); + OTHER_LINKED = (lastcomm.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, lastcomm.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = lastcomm; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/lastcomm/lastcomm.1 b/lastcomm/lastcomm.1 new file mode 100644 index 0000000..11698ce --- /dev/null +++ b/lastcomm/lastcomm.1 @@ -0,0 +1,128 @@ +.\" $NetBSD: lastcomm.1,v 1.7 1997/10/19 03:47:52 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)lastcomm.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt LASTCOMM 1 +.Os BSD 3 +.Sh NAME +.Nm lastcomm +.Nd show last commands executed in reverse order +.Sh SYNOPSIS +.Nm +.Op Fl f Ar file +.Op Ar command ... +.Op Ar user ... +.Op Ar terminal ... +.Sh DESCRIPTION +.Nm +gives information on previously executed commands. +With no arguments, +.Nm +prints information about all the commands recorded +during the current accounting file's lifetime. +.Pp +Option: +.Pp +.Bl -tag -width Fl +.It Fl f Ar file +Read from +.Ar file +rather than the default +accounting file. +.El +.Pp +If called with arguments, only accounting entries with a +matching +.Ar command +name, +.Ar user +name, +or +.Ar terminal +name +are printed. +So, for example: +.Pp +.Dl lastcomm a.out root ttyd0 +.Pp +would produce a listing of all the +executions of commands named +.Pa a.out +by user +.Ar root +on the terminal +.Ar ttyd0 . +.Pp +For each process entry, the following are printed. +.Pp +.Bl -bullet -offset indent -compact +.It +The name of the user who ran the process. +.It +Flags, as accumulated by the accounting facilities in the system. +.It +The command name under which the process was called. +.It +The amount of cpu time used by the process (in seconds). +.It +The time the process started. +.It +The elapsed time of the process. +.El +.Pp +The flags are encoded as follows: ``S'' indicates the command was +executed by the super-user, ``F'' indicates the command ran after +a fork, but without a following +.Xr exec , +``C'' indicates the command was run in PDP-11 compatibility mode +(VAX only), +``D'' indicates the command terminated with the generation of a +.Pa core +file, and ``X'' indicates the command was terminated with a signal. +.Sh FILES +.Bl -tag -width /var/account/acct -compact +.It Pa /var/account/acct +Default accounting file. +.El +.Sh SEE ALSO +.Xr last 1 , +.Xr sigaction 2 , +.Xr acct 5 , +.Xr core 5 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . diff --git a/lastcomm/lastcomm.c b/lastcomm/lastcomm.c new file mode 100644 index 0000000..242d959 --- /dev/null +++ b/lastcomm/lastcomm.c @@ -0,0 +1,240 @@ +/* $NetBSD: lastcomm.c,v 1.14 1998/04/02 10:22:03 kleink Exp $ */ + +/* + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)lastcomm.c 8.2 (Berkeley) 4/29/95"; +#endif +__RCSID("$NetBSD: lastcomm.c,v 1.14 1998/04/02 10:22:03 kleink Exp $"); +#endif /* not lint */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pathnames.h" + +time_t expand __P((u_int)); +char *flagbits __P((int)); +char *getdev __P((dev_t)); +int main __P((int, char **)); +int requested __P((char *[], struct acct *)); +void usage __P((void)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + char *p; + struct acct ab; + struct stat sb; + FILE *fp; + off_t size; + time_t t; + double delta; + int ch; + char *acctfile; + + acctfile = _PATH_ACCT; + while ((ch = getopt(argc, argv, "f:")) != -1) + switch((char)ch) { + case 'f': + acctfile = optarg; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + /* Open the file. */ + if ((fp = fopen(acctfile, "r")) == NULL || fstat(fileno(fp), &sb)) + err(1, "%s", acctfile); + + /* + * Round off to integral number of accounting records, probably + * not necessary, but it doesn't hurt. + */ + size = sb.st_size - sb.st_size % sizeof(struct acct); + + /* Check if any records to display. */ + if (size < sizeof(struct acct)) + exit(0); + + /* + * Seek to before the last entry in the file; use lseek(2) in case + * the file is bigger than a "long". + */ + size -= sizeof(struct acct); + if (lseek(fileno(fp), size, SEEK_SET) == -1) + err(1, "%s", acctfile); + + for (;;) { + if (fread(&ab, sizeof(struct acct), 1, fp) != 1) + err(1, "%s", acctfile); + + if (ab.ac_comm[0] == '\0') { + ab.ac_comm[0] = '?'; + ab.ac_comm[1] = '\0'; + } else + for (p = &ab.ac_comm[0]; + p < &ab.ac_comm[fldsiz(acct, ac_comm)] && *p; ++p) + if (!isprint(*p)) + *p = '?'; + if (!*argv || requested(argv, &ab)) { + + t = expand(ab.ac_utime) + expand(ab.ac_stime); + (void)printf( + "%-*.*s %-7s %-*.*s %-*.*s %6.2f secs %.16s", + (int)fldsiz(acct, ac_comm), + (int)fldsiz(acct, ac_comm), + ab.ac_comm, flagbits(ab.ac_flag), + UT_NAMESIZE, UT_NAMESIZE, + user_from_uid(ab.ac_uid, 0), UT_LINESIZE, + UT_LINESIZE, getdev(ab.ac_tty), + t / (double)AHZ, ctime(&ab.ac_btime)); + delta = expand(ab.ac_etime) / (double)AHZ; + printf(" (%1.0f:%02.0f:%05.2f)\n", + delta / SECSPERHOUR, + fmod(delta, SECSPERHOUR) / SECSPERMIN, + fmod(delta, SECSPERMIN)); + } + /* are we at the beginning of the file yet? */ + if (size == 0) + break; + /* seek backward over the one we read and the next to read */ + if (fseek(fp, 2 * -(long)sizeof(struct acct), SEEK_CUR) == -1) + err(1, "%s", acctfile); + /* and account for its size */ + size -= sizeof(struct acct); + } + exit(0); +} + +time_t +expand(t) + u_int t; +{ + time_t nt; + + nt = t & 017777; + t >>= 13; + while (t) { + t--; + nt <<= 3; + } + return (nt); +} + +char * +flagbits(f) + int f; +{ + static char flags[20] = "-"; + char *p; + +#define BIT(flag, ch) if (f & flag) *p++ = ch + + p = flags + 1; + BIT(ASU, 'S'); + BIT(AFORK, 'F'); + BIT(ACOMPAT, 'C'); + BIT(ACORE, 'D'); + BIT(AXSIG, 'X'); + *p = '\0'; + return (flags); +} + +int +requested(argv, acp) + char *argv[]; + struct acct *acp; +{ + do { + if (!strcmp(user_from_uid(acp->ac_uid, 0), *argv)) + return (1); + if (!strcmp(getdev(acp->ac_tty), *argv)) + return (1); + if (!strncmp(acp->ac_comm, *argv, fldsiz(acct, ac_comm))) + return (1); + } while (*++argv); + return (0); +} + +char * +getdev(dev) + dev_t dev; +{ + static dev_t lastdev = (dev_t)-1; + static char *lastname; + + if (dev == NODEV) /* Special case. */ + return ("__"); + if (dev == lastdev) /* One-element cache. */ + return (lastname); + lastdev = dev; + if ((lastname = devname(dev, S_IFCHR)) == NULL) + lastname = "??"; + return (lastname); +} + +void +usage() +{ + (void)fprintf(stderr, + "lastcomm [ -f file ] [command ...] [user ...] [tty ...]\n"); + exit(1); +} diff --git a/lastcomm/pathnames.h b/lastcomm/pathnames.h new file mode 100644 index 0000000..963d279 --- /dev/null +++ b/lastcomm/pathnames.h @@ -0,0 +1,40 @@ +/* $NetBSD: pathnames.h,v 1.3 1994/12/22 01:07:05 jtc Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 + */ + +#include + +#define _PATH_ACCT "/var/account/acct" diff --git a/locate/Makefile b/locate/Makefile new file mode 100644 index 0000000..16bdac7 --- /dev/null +++ b/locate/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = locate + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Aggregate + +TOOLS = bigram code locate + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = aggregate.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/locate/Makefile.postamble b/locate/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/locate/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/locate/Makefile.preamble b/locate/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/locate/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/locate/PB.project b/locate/PB.project new file mode 100644 index 0000000..fc0f9e8 --- /dev/null +++ b/locate/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble); + SUBPROJECTS = (bigram, code, locate); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = locate; + PROJECTTYPE = Aggregate; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/locate/bigram/Makefile b/locate/bigram/Makefile new file mode 100644 index 0000000..3916131 --- /dev/null +++ b/locate/bigram/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = locate.bigram + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = locate.bigram.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/libexec +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/locate/bigram/Makefile.postamble b/locate/bigram/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/locate/bigram/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/locate/bigram/Makefile.preamble b/locate/bigram/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/locate/bigram/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/locate/bigram/PB.project b/locate/bigram/PB.project new file mode 100644 index 0000000..7a75474 --- /dev/null +++ b/locate/bigram/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (locate.bigram.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/libexec; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = locate.bigram; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/locate/bigram/locate.bigram.c b/locate/bigram/locate.bigram.c new file mode 100644 index 0000000..89a87eb --- /dev/null +++ b/locate/bigram/locate.bigram.c @@ -0,0 +1,95 @@ +/* $NetBSD: locate.bigram.c,v 1.6 1997/10/19 04:11:52 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * James A. Woods. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)locate.bigram.c 8.2 (Berkeley) 4/28/95"; +#endif +__RCSID("$NetBSD: locate.bigram.c,v 1.6 1997/10/19 04:11:52 lukem Exp $"); +#endif /* not lint */ + +/* + * bigram < text > bigrams + * + * List bigrams for 'updatedb' script. + * Use 'code' to encode a file using this output. + */ + +#include +#include /* for MAXPATHLEN */ + +char buf1[MAXPATHLEN] = " "; +char buf2[MAXPATHLEN]; + +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + char *cp; + char *oldpath = buf1, *path = buf2; + + while ( fgets ( path, sizeof(buf2), stdin ) != NULL ) { + + /* skip longest common prefix */ + for ( cp = path; *cp == *oldpath; cp++, oldpath++ ) + if ( *oldpath == '\0' ) + break; + /* + * output post-residue bigrams only + */ + while ( *cp != '\0' && *(cp + 1) != '\0' ) { + putchar ( *cp++ ); + putchar ( *cp++ ); + putchar ( '\n' ); + } + if ( path == buf1 ) /* swap pointers */ + path = buf2, oldpath = buf1; + else + path = buf1, oldpath = buf2; + } + return (0); +} diff --git a/locate/code/Makefile b/locate/code/Makefile new file mode 100644 index 0000000..602ceb7 --- /dev/null +++ b/locate/code/Makefile @@ -0,0 +1,49 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = locate.code + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = locate.code.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/libexec +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +HEADER_PATHS = -I../locate + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/locate/code/Makefile.postamble b/locate/code/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/locate/code/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/locate/code/Makefile.preamble b/locate/code/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/locate/code/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/locate/code/PB.project b/locate/code/PB.project new file mode 100644 index 0000000..af49ac1 --- /dev/null +++ b/locate/code/PB.project @@ -0,0 +1,28 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + HEADERSEARCH = (../locate); + H_FILES = (); + OTHER_LINKED = (locate.code.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/libexec; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = locate.code; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/locate/code/locate.code.c b/locate/code/locate.code.c new file mode 100644 index 0000000..c3a262e --- /dev/null +++ b/locate/code/locate.code.c @@ -0,0 +1,220 @@ +/* $NetBSD: locate.code.c,v 1.6 1997/10/19 04:11:54 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * James A. Woods. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)locate.code.c 8.4 (Berkeley) 5/4/95"; +#endif +__RCSID("$NetBSD: locate.code.c,v 1.6 1997/10/19 04:11:54 lukem Exp $"); +#endif /* not lint */ + +/* + * PURPOSE: sorted list compressor (works with a modified 'find' + * to encode/decode a filename database) + * + * USAGE: bigram < list > bigrams + * process bigrams (see updatedb) > common_bigrams + * code common_bigrams < list > squozen_list + * + * METHOD: Uses 'front compression' (see ";login:", Volume 8, Number 1 + * February/March 1983, p. 8). Output format is, per line, an + * offset differential count byte followed by a partially bigram- + * encoded ascii residue. A bigram is a two-character sequence, + * the first 128 most common of which are encoded in one byte. + * + * EXAMPLE: For simple front compression with no bigram encoding, + * if the input is... then the output is... + * + * /usr/src 0 /usr/src + * /usr/src/cmd/aardvark.c 8 /cmd/aardvark.c + * /usr/src/cmd/armadillo.c 14 armadillo.c + * /usr/tmp/zoo 5 tmp/zoo + * + * The codes are: + * + * 0-28 likeliest differential counts + offset to make nonnegative + * 30 switch code for out-of-range count to follow in next word + * 128-255 bigram codes (128 most common, as determined by 'updatedb') + * 32-127 single character (printable) ascii residue (ie, literal) + * + * SEE ALSO: updatedb.csh, bigram.c + * + * AUTHOR: James A. Woods, Informatics General Corp., + * NASA Ames Research Center, 10/82 + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include "locate.h" + +#define BGBUFSIZE (NBG * 2) /* size of bigram buffer */ + +char buf1[MAXPATHLEN] = " "; +char buf2[MAXPATHLEN]; +char bigrams[BGBUFSIZE + 1] = { 0 }; + +int bgindex __P((char *)); +int main __P((int, char **)); +void usage __P((void)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + char *cp, *oldpath, *path; + int ch, code, count, diffcount, oldcount; + FILE *fp; + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 1) + usage(); + + if ((fp = fopen(argv[0], "r")) == NULL) + err(1, "%s", argv[0]); + + /* First copy bigram array to stdout. */ + (void)fgets(bigrams, BGBUFSIZE + 1, fp); + if (fwrite(bigrams, 1, BGBUFSIZE, stdout) != BGBUFSIZE) + err(1, "stdout"); + (void)fclose(fp); + + oldpath = buf1; + path = buf2; + oldcount = 0; + while (fgets(path, sizeof(buf2), stdin) != NULL) { + /* Truncate newline. */ + cp = path + strlen(path) - 1; + if (cp > path && *cp == '\n') + *cp = '\0'; + + /* Squelch characters that would botch the decoding. */ + for (cp = path; *cp != '\0'; cp++) { + *cp &= PARITY-1; + if (*cp <= SWITCH) + *cp = '?'; + } + + /* Skip longest common prefix. */ + for (cp = path; *cp == *oldpath; cp++, oldpath++) + if (*oldpath == '\0') + break; + count = cp - path; + diffcount = count - oldcount + OFFSET; + oldcount = count; + if (diffcount < 0 || diffcount > 2 * OFFSET) { + if (putchar(SWITCH) == EOF || + putw(diffcount, stdout) == EOF) + err(1, "stdout"); + } else + if (putchar(diffcount) == EOF) + err(1, "stdout"); + + while (*cp != '\0') { + if (*(cp + 1) == '\0') { + if (putchar(*cp) == EOF) + err(1, "stdout"); + break; + } + if ((code = bgindex(cp)) < 0) { + if (putchar(*cp++) == EOF || + putchar(*cp++) == EOF) + err(1, "stdout"); + } else { + /* Found, so mark byte with parity bit. */ + if (putchar((code / 2) | PARITY) == EOF) + err(1, "stdout"); + cp += 2; + } + } + if (path == buf1) { /* swap pointers */ + path = buf2; + oldpath = buf1; + } else { + path = buf1; + oldpath = buf2; + } + } + /* Non-zero status if there were errors */ + if (fflush(stdout) != 0 || ferror(stdout)) + exit(1); + exit(0); +} + +int +bgindex(bg) /* Return location of bg in bigrams or -1. */ + char *bg; +{ + char bg0, bg1, *p; + + bg0 = bg[0]; + bg1 = bg[1]; + for (p = bigrams; *p != '\0'; p++) + if (*p++ == bg0 && *p == bg1) + break; + return (*p == '\0' ? -1 : --p - bigrams); +} + +void +usage() +{ + (void)fprintf(stderr, + "usage: locate.code common_bigrams < list > squozen_list\n"); + exit(1); +} diff --git a/locate/locate/Makefile b/locate/locate/Makefile new file mode 100644 index 0000000..c50d9fa --- /dev/null +++ b/locate/locate/Makefile @@ -0,0 +1,51 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = locate + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = locate.h pathnames.h + +CFILES = locate.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble locate.1\ + updatedb.csh + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/locate/locate/Makefile.postamble b/locate/locate/Makefile.postamble new file mode 100644 index 0000000..abf00eb --- /dev/null +++ b/locate/locate/Makefile.postamble @@ -0,0 +1,5 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common + +after_install:: + $(CP) updatedb.csh $(DSTROOT)/usr/libexec/locate.updatedb + $(CHMOD) 555 $(DSTROOT)/usr/libexec/locate.updatedb diff --git a/locate/locate/Makefile.preamble b/locate/locate/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/locate/locate/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/locate/locate/PB.project b/locate/locate/PB.project new file mode 100644 index 0000000..e2d36fe --- /dev/null +++ b/locate/locate/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (locate.h, pathnames.h); + OTHER_LINKED = (locate.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, locate.1, updatedb.csh); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = locate; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/locate/locate/locate.1 b/locate/locate/locate.1 new file mode 100644 index 0000000..8ebdbae --- /dev/null +++ b/locate/locate/locate.1 @@ -0,0 +1,87 @@ +.\" $NetBSD: locate.1,v 1.6 1998/08/08 14:49:23 hubertf Exp $ +.\" +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)locate.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt LOCATE 1 +.Os BSD 4.4 +.Sh NAME +.Nm locate +.Nd find files +.Sh SYNOPSIS +.Nm +.Ar pattern +.Sh DESCRIPTION +.Nm +searches a database for all pathnames which match the specified +.Ar pattern . +The database is recomputed periodically, and contains the pathnames +of all files which are publicly accessible. +.Pp +Shell globbing and quoting characters (``*'', ``?'', ``\e'', ``['' +and ``]'') +may be used in +.Ar pattern , +although they will have to be escaped from the shell. +Preceding any character with a backslash (``\e'') eliminates any special +meaning which it may have. +The matching differs in that no characters must be matched explicitly, +including slashes (``/''). +.Pp +As a special case, a pattern containing no globbing characters (``foo'') +is matched as though it were ``*foo*''. +.Sh FILES +.Bl -tag -width /usr/libexec/locate.updatedb -compact +.It Pa /var/db/locate.database +Database +.It /usr/libexec/locate.updatedb +Script to update database. +.El +.Sh SEE ALSO +.Xr find 1 , +.Xr fnmatch 3 , +.Xr weekly.conf 5 +.Rs +.%A Woods, James A. +.%D 1983 +.%T "Finding Files Fast" +.%J ";login" +.%V 8:1 +.%P pp. 8-10 +.Re +.Sh HISTORY +The +.Nm +command appears in +.Bx 4.4 . diff --git a/locate/locate/locate.c b/locate/locate/locate.c new file mode 100644 index 0000000..a780f05 --- /dev/null +++ b/locate/locate/locate.c @@ -0,0 +1,206 @@ +/* $NetBSD: locate.c,v 1.8 1997/10/19 04:11:56 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * James A. Woods. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)locate.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: locate.c,v 1.8 1997/10/19 04:11:56 lukem Exp $"); +#endif /* not lint */ + +/* + * Ref: Usenix ;login:, Vol 8, No 1, February/March, 1983, p. 8. + * + * Locate scans a file list for the full pathname of a file given only part + * of the name. The list has been processed with with "front-compression" + * and bigram coding. Front compression reduces space by a factor of 4-5, + * bigram coding by a further 20-25%. + * + * The codes are: + * + * 0-28 likeliest differential counts + offset to make nonnegative + * 30 switch code for out-of-range count to follow in next word + * 128-255 bigram codes (128 most common, as determined by 'updatedb') + * 32-127 single character (printable) ascii residue (ie, literal) + * + * A novel two-tiered string search technique is employed: + * + * First, a metacharacter-free subpattern and partial pathname is matched + * BACKWARDS to avoid full expansion of the pathname list. The time savings + * is 40-50% over forward matching, which cannot efficiently handle + * overlapped search patterns and compressed path residue. + * + * Then, the actual shell glob-style regular expression (if in this form) is + * matched against the candidate pathnames using the slower routines provided + * in the standard 'find'. + */ + +#include + +#include +#include +#include +#include + +#include "locate.h" +#include "pathnames.h" + +void fastfind __P((char *)); +int main __P((int, char **)); +char *patprep __P((char *)); + +FILE *fp; + +int +main(argc, argv) + int argc; + char *argv[]; +{ + if (argc != 2) { + (void)fprintf(stderr, "usage: locate pattern\n"); + exit(1); + } + if (!(fp = fopen(_PATH_FCODES, "r"))) { + (void)fprintf(stderr, "locate: no database file %s.\n", + _PATH_FCODES); + exit(1); + } + while (*++argv) + fastfind(*argv); + exit(0); +} + +void +fastfind(pathpart) + char *pathpart; +{ + char *p, *s; + int c; + int count, found, globflag; + char *cutoff, *patend, *q; + char bigram1[NBG], bigram2[NBG], path[MAXPATHLEN]; + + for (c = 0, p = bigram1, s = bigram2; c < NBG; c++) + p[c] = getc(fp), s[c] = getc(fp); + + p = pathpart; + globflag = strchr(p, '*') || strchr(p, '?') || strchr(p, '['); + patend = patprep(p); + + found = 0; + for (c = getc(fp), count = 0; c != EOF;) { + count += ((c == SWITCH) ? getw(fp) : c) - OFFSET; + /* overlay old path */ + for (p = path + count; (c = getc(fp)) > SWITCH;) + if (c < PARITY) + *p++ = c; + else { /* bigrams are parity-marked */ + c &= PARITY - 1; + *p++ = bigram1[c], *p++ = bigram2[c]; + } + *p-- = '\0'; + cutoff = (found ? path : path + count); + for (found = 0, s = p; s >= cutoff; s--) + if (*s == *patend) { /* fast first char check */ + for (p = patend - 1, q = s - 1; *p != '\0'; + p--, q--) + if (*q != *p) + break; + if (*p == '\0') { /* fast match success */ + found = 1; + if (!globflag || + !fnmatch(pathpart, path, 0)) + (void)printf("%s\n", path); + break; + } + } + } +} + +/* + * extract last glob-free subpattern in name for fast pre-match; prepend + * '\0' for backwards match; return end of new pattern + */ +static char globfree[100]; + +char * +patprep(name) + char *name; +{ + char *endmark, *p, *subp; + + subp = globfree; + *subp++ = '\0'; + p = name + strlen(name) - 1; + /* skip trailing metacharacters (and [] ranges) */ + for (; p >= name; p--) + if (strchr("*?", *p) == 0) + break; + if (p < name) + p = name; + if (*p == ']') + for (p--; p >= name; p--) + if (*p == '[') { + p--; + break; + } + if (p < name) + p = name; + /* + * if pattern has only metacharacters, check every path (force '/' + * search) + */ + if ((p == name) && strchr("?*[]", *p) != 0) + *subp++ = '/'; + else { + for (endmark = p; p >= name; p--) + if (strchr("]*?", *p) != 0) + break; + for (++p; + (p <= endmark) && subp < (globfree + sizeof(globfree));) + *subp++ = *p++; + } + *subp = '\0'; + return(--subp); +} diff --git a/locate/locate/locate.h b/locate/locate/locate.h new file mode 100644 index 0000000..467c2cb --- /dev/null +++ b/locate/locate/locate.h @@ -0,0 +1,43 @@ +/* $NetBSD: locate.h,v 1.3 1994/12/22 06:17:48 jtc Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)locate.h 8.1 (Berkeley) 6/6/93 + */ + +/* Symbolic constants shared by locate.c and code.c */ + +#define NBG 128 /* number of bigrams considered */ +#define OFFSET 14 /* abs value of max likely diff */ +#define PARITY 0200 /* parity bit */ +#define SWITCH 30 /* switch code */ diff --git a/locate/locate/pathnames.h b/locate/locate/pathnames.h new file mode 100644 index 0000000..8021ffe --- /dev/null +++ b/locate/locate/pathnames.h @@ -0,0 +1,38 @@ +/* $NetBSD: pathnames.h,v 1.3 1994/12/22 06:17:49 jtc Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 + */ + +#define _PATH_FCODES "/var/db/locate.database" diff --git a/locate/locate/updatedb.csh b/locate/locate/updatedb.csh new file mode 100644 index 0000000..d98f902 --- /dev/null +++ b/locate/locate/updatedb.csh @@ -0,0 +1,81 @@ +#!/bin/csh -f +# +# $NetBSD: updatedb.csh,v 1.7 1995/08/31 22:36:35 jtc Exp $ +# +# Copyright (c) 1989, 1993 +# The Regents of the University of California. All rights reserved. +# +# This code is derived from software contributed to Berkeley by +# James A. Woods. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the University of +# California, Berkeley and its contributors. +# 4. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# @(#)updatedb.csh 8.4 (Berkeley) 10/27/94 +# + +set SRCHPATHS = "/" # directories to be put in the database +set LIBDIR = /usr/libexec # for subprograms + # for temp files +if (! $?TMPDIR) setenv TMPDIR /var/tmp +if (! $?DBDIR) setenv DBDIR /var/db +set FCODES = $DBDIR/locate.database # the database + +set path = ( /bin /usr/bin ) +set bigrams = $TMPDIR/locate.bigrams.$$ +set filelist = $TMPDIR/locate.list.$$ +set errs = $TMPDIR/locate.errs.$$ + +# Make a file list and compute common bigrams. +# Alphabetize '/' before any other char with 'tr'. +# If the system is very short of sort space, 'bigram' can be made +# smarter to accumulate common bigrams directly without sorting +# ('awk', with its associative memory capacity, can do this in several +# lines, but is too slow, and runs out of string space on small machines). + +# search locally or everything +# find ${SRCHPATHS} -print | \ +find ${SRCHPATHS} \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \) -a \ + -prune -o -print | \ + tr '/' '\001' | \ + (sort -T "$TMPDIR" -f; echo $status > $errs) | tr '\001' '/' > $filelist + +$LIBDIR/locate.bigram < $filelist | \ + (sort -T "$TMPDIR"; echo $status >> $errs) | \ + uniq -c | sort -T "$TMPDIR" -nr | \ + awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams + +# code the file list + +if { grep -s -v 0 $errs } then + printf 'locate: updatedb failed\n\n' +else + $LIBDIR/locate.code $bigrams < $filelist > $FCODES + chmod 644 $FCODES + rm $bigrams $filelist $errs +endif diff --git a/logname/Makefile b/logname/Makefile new file mode 100644 index 0000000..a35d67c --- /dev/null +++ b/logname/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = logname + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = logname.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble logname.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/logname/Makefile.postamble b/logname/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/logname/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/logname/Makefile.preamble b/logname/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/logname/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/logname/PB.project b/logname/PB.project new file mode 100644 index 0000000..53e4435 --- /dev/null +++ b/logname/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (logname.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, logname.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = logname; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/logname/logname.1 b/logname/logname.1 new file mode 100644 index 0000000..4d2a508 --- /dev/null +++ b/logname/logname.1 @@ -0,0 +1,78 @@ +.\" $NetBSD: logname.1,v 1.8 1997/10/19 04:20:06 lukem Exp $ +.\" +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)logname.1 8.1 (Berkeley) 6/9/93 +.\" +.Dd June 9, 1993 +.Dt LOGNAME 1 +.Os BSD 4.4 +.Sh NAME +.Nm logname +.Nd display user's login name +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +utility writes the user's login name to standard output followed by +a newline. +.Pp +The +.Nm +utility explicitly ignores the +.Ev LOGNAME +and +.Ev USER +environment variables +because the environment cannot be trusted. +.Pp +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Sh SEE ALSO +.Xr who 1 , +.Xr whoami 1 , +.Xr getlogin 2 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.4 . diff --git a/logname/logname.c b/logname/logname.c new file mode 100644 index 0000000..ed63ffe --- /dev/null +++ b/logname/logname.c @@ -0,0 +1,92 @@ +/* $NetBSD: logname.c,v 1.7 1997/10/19 04:20:06 lukem Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)logname.c 8.2 (Berkeley) 4/3/94"; +#endif +__RCSID("$NetBSD: logname.c,v 1.7 1997/10/19 04:20:06 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include + +int main __P((int, char **)); +void usage __P((void)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int ch; + char *p; + + setlocale(LC_ALL, ""); + + while ((ch = getopt(argc, argv, "")) != -1) + switch (ch) { + case '?': + default: + usage(); + /* NOTREACHED */ + } + + if (argc != optind) { + usage(); + /* NOTREACHED */ + } + + if ((p = getlogin()) == NULL) + err(1, "getlogin"); + (void)printf("%s\n", p); + exit(0); +} + +void +usage() +{ + (void)fprintf(stderr, "usage: logname\n"); + exit(1); +} diff --git a/nice/Makefile b/nice/Makefile new file mode 100644 index 0000000..6a4546b --- /dev/null +++ b/nice/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = nice + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = nice.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble nice.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/nice/Makefile.postamble b/nice/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/nice/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/nice/Makefile.preamble b/nice/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/nice/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/nice/PB.project b/nice/PB.project new file mode 100644 index 0000000..56d2c0e --- /dev/null +++ b/nice/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (nice.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, nice.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = nice; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/nice/nice.1 b/nice/nice.1 new file mode 100644 index 0000000..4dba5c9 --- /dev/null +++ b/nice/nice.1 @@ -0,0 +1,120 @@ +.\" $NetBSD: nice.1,v 1.8 1997/10/19 06:28:02 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)nice.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt NICE 1 +.Os +.Sh NAME +.Nm nice +.Nd execute a utility with an altered scheduling priority +.Sh SYNOPSIS +.Nm +.Op Fl n Ar increment +.Ar utility +.Op Ar argument ... +.Sh DESCRIPTION +.Nm +runs +.Ar utility +at an altered scheduling priority. +If an +.Ar increment +is given, it is used; otherwise +an increment of 10 is assumed. +The super-user can run utilities with priorities higher than normal by using +a negative +.Ar increment . +The priority can be adjusted over a +range of -20 (the highest) to 20 (the lowest). +.Pp +Available options: +.Bl -tag -width indent +.It Fl n Ar increment +A positive or negative decimal integer used to modify the system scheduling +priority of +.Ar utility. +.El +.Sh DIAGNOSTICS +The +.Nm +utility shall exit with one of the following values: +.Bl -tag -width indent +.It 1-125 +An error occurred in the +.Nm +utility. +.It 126 +The +.Ar utility +was found but could not be invoked. +.It 127 +The +.Ar utility +could not be found. +.El +.Pp +Otherwise, the exit status of +.Nm +shall be that of +.Ar utility . +.Sh COMPATIBILITY +The historic +.Fl Ns Ar increment +option has been deprecated but is still supported in this implementation. +.Sh SEE ALSO +.Xr csh 1 , +.Xr getpriority 2 , +.Xr setpriority 2 , +.Xr renice 8 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . +.Sh HISTORY +A +.Nm +utility appeared in +.At v6 . +.Sh BUGS +.Nm +is built into +.Xr csh 1 +with a slightly different syntax than described here. The form +.Ql nice +10 +nices to positive nice, and +.Ql nice \-10 +can be used +by the super-user to give a process more of the processor. diff --git a/nice/nice.c b/nice/nice.c new file mode 100644 index 0000000..62a197e --- /dev/null +++ b/nice/nice.c @@ -0,0 +1,122 @@ +/* $NetBSD: nice.c,v 1.10 1997/10/19 06:28:04 lukem Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( + "@(#) Copyright (c) 1989 The Regents of the University of California.\n\ + All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)nice.c 5.4 (Berkeley) 6/1/90"; +#endif +__RCSID("$NetBSD: nice.c,v 1.10 1997/10/19 06:28:04 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFNICE 10 + +int main __P((int, char **)); +static void usage __P((void)); + +int +main(argc, argv) + int argc; + char **argv; +{ + int niceness = DEFNICE; + int c; + + setlocale(LC_ALL, ""); + + /* handle obsolete -number syntax */ + if (argc > 1 && argv[1][0] == '-' && isdigit(argv[1][1])) { + niceness = atoi (argv[1] + 1); + argc--; argv++; + } + + while ((c = getopt (argc, argv, "n:")) != -1) { + switch (c) { + case 'n': + niceness = atoi (optarg); + break; + + case '?': + default: + usage(); + break; + } + } + argc -= optind; argv += optind; + + if (argc == 0) + usage(); + + errno = 0; + niceness += getpriority(PRIO_PROCESS, 0); + if (errno) { + err (1, "getpriority"); + /* NOTREACHED */ + } + if (setpriority(PRIO_PROCESS, 0, niceness)) { + warn ("setpriority"); + } + + execvp(argv[0], &argv[0]); + err ((errno == ENOENT) ? 127 : 126, "%s", argv[0]); + /* NOTREACHED */ +} + +static void +usage() +{ + (void)fprintf(stderr, + "usage: nice [ -n increment ] utility [ argument ...]\n"); + + exit(1); +} diff --git a/nohup/Makefile b/nohup/Makefile new file mode 100644 index 0000000..43fb24e --- /dev/null +++ b/nohup/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = nohup + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = nohup.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble nohup.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/nohup/Makefile.postamble b/nohup/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/nohup/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/nohup/Makefile.preamble b/nohup/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/nohup/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/nohup/PB.project b/nohup/PB.project new file mode 100644 index 0000000..ba1f220 --- /dev/null +++ b/nohup/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (nohup.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, nohup.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = nohup; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/nohup/nohup.1 b/nohup/nohup.1 new file mode 100644 index 0000000..c60a263 --- /dev/null +++ b/nohup/nohup.1 @@ -0,0 +1,105 @@ +.\" $NetBSD: nohup.1,v 1.6 1997/10/19 10:23:25 lukem Exp $ +.\" +.\" Copyright (c) 1989, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)nohup.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt NOHUP 1 +.Os +.Sh NAME +.Nm nohup +.Nd invoke a command immune to hangups +.Sh SYNOPSIS +.Nm +.Ar utility +.Op Ar arg ... +.Sh DESCRIPTION +The +.Nm +utility invokes +.Ar command +with +its arguments +and at this time sets the signal +.Dv SIGHUP +to be ignored. +If the standard output is a terminal, the standard output is +appended to the file +.Pa nohup.out +in the current directory. +If standard error is a terminal, it is directed to the same place +as the standard output. +.Sh ENVIRONMENT +The following variable is utilized by +.Nm "" . +.Bl -tag -width flag +.It Ev HOME +If the output file +.Pa nohup.out +cannot be created in the current directory, the +.Nm +utility uses the directory named by +.Ev HOME +to create the file. +.El +.Sh DIAGNOSTICS +The +.Nm +utility shall exit with one of the following values: +.Bl -tag -width Ds +.It 126 +The +.Ar utility +was found but could not be invoked. +.It 127 +The +.Ar utility +could not be found or an error occurred in +.Nm "" . +.El +.Pp +Otherwise, the exit status of +.Nm +shall be that of +.Ar utility . +.Sh SEE ALSO +.Xr signal 3 +.Sh STANDARDS +The +.Nm +command is expected to be +.St -p1003.2 +compatible. diff --git a/nohup/nohup.c b/nohup/nohup.c new file mode 100644 index 0000000..e939a7d --- /dev/null +++ b/nohup/nohup.c @@ -0,0 +1,143 @@ +/* $NetBSD: nohup.c,v 1.8 1997/12/23 18:21:34 ross Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( + "@(#) Copyright (c) 1989 The Regents of the University of California.\n\ + All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)nohup.c 5.4 (Berkeley) 6/1/90"; +#endif +__RCSID("$NetBSD: nohup.c,v 1.8 1997/12/23 18:21:34 ross Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void dofile __P((void)); +static void usage __P((void)); +int main __P((int, char **)); + +/* nohup shall exit with one of the following values: + 126 - The utility was found but could not be invoked. + 127 - An error occured in the nohup utility, or the utility could + not be found. */ +#define EXIT_NOEXEC 126 +#define EXIT_NOTFOUND 127 +#define EXIT_MISC 127 + +int +main(argc, argv) + int argc; + char **argv; +{ + int exit_status; + + if (argc < 2) + usage(); + + if (isatty(STDOUT_FILENO)) + dofile(); + if (isatty(STDERR_FILENO) && dup2(STDOUT_FILENO, STDERR_FILENO) == -1) { + /* may have just closed stderr */ + (void)fprintf(stdin, "nohup: %s\n", strerror(errno)); + exit(EXIT_MISC); + } + + /* The nohup utility shall take the standard action for all signals + except that SIGHUP shall be ignored. */ + (void)signal(SIGHUP, SIG_IGN); + + execvp(argv[1], &argv[1]); + exit_status = (errno == ENOENT) ? EXIT_NOTFOUND : EXIT_NOEXEC; + (void)fprintf(stderr, "nohup: %s: %s\n", argv[1], strerror(errno)); + exit(exit_status); +} + +static void +dofile() +{ + int fd; + char *p, path[MAXPATHLEN]; + + /* If the standard output is a terminal, all output written to + its standard output shall be appended to the end of the file + nohup.out in the current directory. If nohup.out cannot be + created or opened for appending, the output shall be appended + to the end of the file nohup.out in the directory specified + by the HOME environment variable. + + If a file is created, the file's permission bits shall be + set to S_IRUSR | S_IWUSR. */ +#define FILENAME "nohup.out" + p = FILENAME; + if ((fd = open(p, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR)) >= 0) + goto dupit; + if ((p = getenv("HOME")) != NULL) { + (void)strcpy(path, p); + (void)strcat(path, "/"); + (void)strcat(path, FILENAME); + if ((fd = open(p = path, O_RDWR|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR)) >= 0) + goto dupit; + } + (void)fprintf(stderr, "nohup: can't open a nohup.out file.\n"); + exit(EXIT_MISC); + +dupit: (void)lseek(fd, 0L, SEEK_END); + if (dup2(fd, STDOUT_FILENO) == -1) { + (void)fprintf(stderr, "nohup: %s\n", strerror(errno)); + exit(EXIT_MISC); + } + (void)fprintf(stderr, "sending output to %s\n", p); +} + +static void +usage() +{ + (void)fprintf(stderr, "usage: nohup command\n"); + exit(EXIT_MISC); +} diff --git a/printenv/Makefile b/printenv/Makefile new file mode 100644 index 0000000..638e2d1 --- /dev/null +++ b/printenv/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = printenv + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = printenv.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble printenv.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/printenv/Makefile.postamble b/printenv/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/printenv/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/printenv/Makefile.preamble b/printenv/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/printenv/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/printenv/PB.project b/printenv/PB.project new file mode 100644 index 0000000..64baf1f --- /dev/null +++ b/printenv/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (printenv.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, printenv.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = printenv; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/printenv/printenv.1 b/printenv/printenv.1 new file mode 100644 index 0000000..ea3fb0f --- /dev/null +++ b/printenv/printenv.1 @@ -0,0 +1,69 @@ +.\" $NetBSD: printenv.1,v 1.5 1997/10/19 12:44:21 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)printenv.1 8.1 (Berkeley) 6/6/93 +.\" $NetBSD: printenv.1,v 1.5 1997/10/19 12:44:21 lukem Exp $ +.\" +.Dd June 6, 1993 +.Dt PRINTENV 1 +.Os +.Sh NAME +.Nm printenv +.Nd print out the environment +.Sh SYNOPSIS +.Nm +.Op Ar name +.Sh DESCRIPTION +.Nm +prints out the names and values of the variables in the environment, +with one name/value pair per line. If +.Ar name +is specified, only +its value is printed. +.Pp +If a +.Ar name +is specified and it is not defined in the environment, +.Nm +returns exit status 1, else it returns status 0. +.Sh SEE ALSO +.Xr csh 1 , +.Xr sh 1 , +.Xr environ 7 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . diff --git a/printenv/printenv.c b/printenv/printenv.c new file mode 100644 index 0000000..be8b50b --- /dev/null +++ b/printenv/printenv.c @@ -0,0 +1,104 @@ +/* $NetBSD: printenv.c,v 1.6 1997/10/19 12:44:26 lukem Exp $ */ + +/* + * Copyright (c) 1987, 1993 + * Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +/*static char sccsid[] = "from: @(#)printenv.c 8.2 (Berkeley) 5/4/95";*/ +__RCSID("$NetBSD: printenv.c,v 1.6 1997/10/19 12:44:26 lukem Exp $"); +#endif /* not lint */ + +#include + +#include +#include +#include +#include + +int main __P((int, char **)); +void usage __P((void)); + +/* + * printenv + * + * Bill Joy, UCB + * February, 1979 + */ +int +main(argc, argv) + int argc; + char *argv[]; +{ + extern char **environ; + char *cp, **ep; + size_t len; + int ch; + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc == 0) { + for (ep = environ; *ep; ep++) + (void)printf("%s\n", *ep); + exit(0); + } + len = strlen(*argv); + for (ep = environ; *ep; ep++) + if (!memcmp(*ep, *argv, len)) { + cp = *ep + len; + if (!*cp || *cp == '=') { + (void)printf("%s\n", *cp ? cp + 1 : cp); + exit(0); + } + } + exit(1); +} + +void +usage() +{ + (void)fprintf(stderr, "usage: printenv [name]\n"); + exit(1); +} diff --git a/printf/Makefile b/printf/Makefile new file mode 100644 index 0000000..aaa90fa --- /dev/null +++ b/printf/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = printf + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = printf.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble printf.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/printf/Makefile.postamble b/printf/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/printf/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/printf/Makefile.preamble b/printf/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/printf/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/printf/PB.project b/printf/PB.project new file mode 100644 index 0000000..22c7b78 --- /dev/null +++ b/printf/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (printf.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, printf.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = printf; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/printf/printf.1 b/printf/printf.1 new file mode 100644 index 0000000..bc63d9b --- /dev/null +++ b/printf/printf.1 @@ -0,0 +1,280 @@ +.\" $NetBSD: printf.1,v 1.10 1998/08/22 14:54:48 garbled Exp $ +.\" +.\" Copyright (c) 1989, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)printf.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd November 5, 1993 +.Dt PRINTF 1 +.Os +.Sh NAME +.Nm printf +.Nd formatted output +.Sh SYNOPSIS +.Nm +.Ar format +.Op Ar arguments ... +.Sh DESCRIPTION +.Nm +formats and prints its arguments, after the first, under control +of the +.Ar format . +The +.Ar format +is a character string which contains three types of objects: plain characters, +which are simply copied to standard output, character escape sequences which +are converted and copied to the standard output, and format specifications, +each of which causes printing of the next successive +.Ar argument . +.Pp +The +.Ar arguments +after the first are treated as strings if the corresponding format is +either +.Cm b , +.Cm c +or +.Cm s ; +otherwise it is evaluated as a C constant, with the following extensions: +.Pp +.Bl -bullet -offset indent -compact +.It +A leading plus or minus sign is allowed. +.It +If the leading character is a single or double quote, the value is the +.Tn ASCII +code of the next character. +.El +.Pp +The format string is reused as often as necessary to satisfy the +.Ar arguments . +Any extra format specifications are evaluated with zero or the null +string. +.Pp +Character escape sequences are in backslash notation as defined in +.St -ansiC . +The characters and their meanings +are as follows: +.Bl -tag -width Ds -offset indent +.It Cm \ee +Write an character. +.It Cm \ea +Write a character. +.It Cm \eb +Write a character. +.It Cm \ef +Write a character. +.It Cm \en +Write a character. +.It Cm \er +Write a character. +.It Cm \et +Write a character. +.It Cm \ev +Write a character. +.It Cm \e\' +Write a character. +.It Cm \e\e +Write a backslash character. +.It Cm \e Ns Ar num +Write an 8-bit character whose +.Tn ASCII +value is the 1-, 2-, or 3-digit +octal number +.Ar num . +.El +.Pp +Each format specification is introduced by the percent character +(``%''). +The remainder of the format specification includes, +in the following order: +.Bl -tag -width Ds +.It "Zero or more of the following flags:" +.Bl -tag -width Ds +.It Cm # +A `#' character +specifying that the value should be printed in an ``alternative form''. +For +.Cm c , +.Cm d , +and +.Cm s , +formats, this option has no effect. For the +.Cm o +formats the precision of the number is increased to force the first +character of the output string to a zero. For the +.Cm x +.Pq Cm X +format, a non-zero result has the string +.Li 0x +.Pq Li 0X +prepended to it. For +.Cm e , +.Cm E , +.Cm f , +.Cm g , +and +.Cm G , +formats, the result will always contain a decimal point, even if no +digits follow the point (normally, a decimal point only appears in the +results of those formats if a digit follows the decimal point). For +.Cm g +and +.Cm G +formats, trailing zeros are not removed from the result as they +would otherwise be; +.It Cm \&\- +A minus sign `\-' which specifies +.Em left adjustment +of the output in the indicated field; +.It Cm \&+ +A `+' character specifying that there should always be +a sign placed before the number when using signed formats. +.It Sq \&\ \& +A space specifying that a blank should be left before a positive number +for a signed format. A `+' overrides a space if both are used; +.It Cm \&0 +A zero `0' character indicating that zero-padding should be used +rather than blank-padding. A `\-' overrides a `0' if both are used; +.El +.It "Field Width:" +An optional digit string specifying a +.Em field width ; +if the output string has fewer characters than the field width it will +be blank-padded on the left (or right, if the left-adjustment indicator +has been given) to make up the field width (note that a leading zero +is a flag, but an embedded zero is part of a field width); +.It Precision: +An optional period, +.Sq Cm \&.\& , +followed by an optional digit string giving a +.Em precision +which specifies the number of digits to appear after the decimal point, +for +.Cm e +and +.Cm f +formats, or the maximum number of characters to be printed +from a string; if the digit string is missing, the precision is treated +as zero; +.It Format: +A character which indicates the type of format to use (one of +.Cm diouxXfwEgGbcs ) . +.El +.Pp +A field width or precision may be +.Sq Cm \&* +instead of a digit string. +In this case an +.Ar argument +supplies the field width or precision. +.Pp +The format characters and their meanings are: +.Bl -tag -width Fl +.It Cm diouXx +The +.Ar argument +is printed as a signed decimal (d or i), unsigned octal, unsigned decimal, +or unsigned hexadecimal (X or x), respectively. +.It Cm f +The +.Ar argument +is printed in the style +.Sm off +.Pf [\-]ddd Cm \&. No ddd +.Sm on +where the number of d's +after the decimal point is equal to the precision specification for +the argument. +If the precision is missing, 6 digits are given; if the precision +is explicitly 0, no digits and no decimal point are printed. +.It Cm eE +The +.Ar argument +is printed in the style +.Sm off +.Pf [\-]d Cm \&. No ddd Cm e No \\*(Pmdd +.Sm on +where there +is one digit before the decimal point and the number after is equal to +the precision specification for the argument; when the precision is +missing, 6 digits are produced. +An upper-case E is used for an `E' format. +.It Cm gG +The +.Ar argument +is printed in style +.Cm f +or in style +.Cm e +.Pq Cm E +whichever gives full precision in minimum space. +.It Cm b +Characters from the string +.Ar argument +are printed with backslash-escape sequences expanded. +.It Cm c +The first character of +.Ar argument +is printed. +.It Cm s +Characters from the string +.Ar argument +are printed until the end is reached or until the number of characters +indicated by the precision specification is reached; however if the +precision is 0 or missing, all characters in the string are printed. +.It Cm \&% +Print a `%'; no argument is used. +.El +.Pp +In no case does a non-existent or small field width cause truncation of +a field; padding takes place only if the specified field width exceeds +the actual width. +.Sh RETURN VALUES +.Nm +exits 0 on success, 1 on failure. +.Sh SEE ALSO +.Xr echo 1 , +.Xr printf 3 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . +.Sh BUGS +Since the floating point numbers are translated from +.Tn ASCII +to floating-point and +then back again, floating-point precision may be lost. diff --git a/printf/printf.c b/printf/printf.c new file mode 100644 index 0000000..9ac5fbd --- /dev/null +++ b/printf/printf.c @@ -0,0 +1,550 @@ +/* $NetBSD: printf.c,v 1.19 1998/02/03 03:10:15 perry Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if !defined(BUILTIN) && !defined(SHELL) +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif +#endif + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)printf.c 8.2 (Berkeley) 3/22/95"; +#else +__RCSID("$NetBSD: printf.c,v 1.19 1998/02/03 03:10:15 perry Exp $"); +#endif +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int print_escape_str __P((const char *)); +static size_t print_escape __P((const char *)); + +static int getchr __P((void)); +static double getdouble __P((void)); +static int getint __P((void)); +static long getlong __P((void)); +static unsigned long getulong __P ((void)); +static char *getstr __P((void)); +static char *mklong __P((const char *, int)); +static void check_conversion __P((const char *, const char *)); +static void usage __P((void)); + +static int rval; +static char **gargv; + +#ifdef BUILTIN +int progprintf __P((int, char **)); +#else +int main __P((int, char **)); +#endif + +#define isodigit(c) ((c) >= '0' && (c) <= '7') +#define octtobin(c) ((c) - '0') +#define hextobin(c) ((c) >= 'A' && (c) <= 'F' ? c - 'A' + 10 : (c) >= 'a' && (c) <= 'f' ? c - 'a' + 10 : c - '0') + +#ifdef SHELL +#define main printfcmd +#ifdef __APPLE__ +#include "bltin/bltin.h" +#else +#include "../../bin/sh/bltin/bltin.h" +#endif + +#ifdef __STDC__ +#include +#else +#include +#endif + +static void warnx __P((const char *fmt, ...)); + +static void +#ifdef __STDC__ +warnx(const char *fmt, ...) +#else +warnx(fmt, va_alist) + const char *fmt; + va_dcl +#endif +{ + + char buf[64]; + va_list ap; + +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + vsprintf(buf, fmt, ap); + va_end(ap); + + error(buf); +} +#endif /* SHELL */ + +#define PF(f, func) { \ + if (fieldwidth) \ + if (precision) \ + (void)printf(f, fieldwidth, precision, func); \ + else \ + (void)printf(f, fieldwidth, func); \ + else if (precision) \ + (void)printf(f, precision, func); \ + else \ + (void)printf(f, func); \ +} + +int +#ifdef BUILTIN +progprintf(argc, argv) +#else +main(argc, argv) +#endif + int argc; + char *argv[]; +{ + char *fmt, *start; + int fieldwidth, precision; + char convch, nextch; + char *format; + int ch; + +#if !defined(SHELL) && !defined(BUILTIN) + (void)setlocale (LC_ALL, ""); +#endif + + while ((ch = getopt(argc, argv, "")) != -1) { + switch (ch) { + case '?': + default: + usage(); + return (1); + } + } + argc -= optind; + argv += optind; + + if (argc < 1) { + usage(); + return (1); + } + + format = *argv; + gargv = ++argv; + +#define SKIP1 "#-+ 0" +#define SKIP2 "*0123456789" + do { + /* + * Basic algorithm is to scan the format string for conversion + * specifications -- once one is found, find out if the field + * width or precision is a '*'; if it is, gather up value. + * Note, format strings are reused as necessary to use up the + * provided arguments, arguments of zero/null string are + * provided to use up the format string. + */ + + /* find next format specification */ + for (fmt = format; *fmt; fmt++) { + switch (*fmt) { + case '%': + start = fmt++; + + if (*fmt == '%') { + (void)putchar('%'); + break; + } else if (*fmt == 'b') { + char *p = getstr(); + if (print_escape_str(p)) { + return (rval); + } + break; + } + + /* skip to field width */ + for (; strchr(SKIP1, *fmt); ++fmt) ; + fieldwidth = *fmt == '*' ? getint() : 0; + + /* skip to possible '.', get following precision */ + for (; strchr(SKIP2, *fmt); ++fmt) ; + if (*fmt == '.') + ++fmt; + precision = *fmt == '*' ? getint() : 0; + + for (; strchr(SKIP2, *fmt); ++fmt) ; + if (!*fmt) { + warnx ("missing format character"); + return(1); + } + + convch = *fmt; + nextch = *(fmt + 1); + *(fmt + 1) = '\0'; + switch(convch) { + case 'c': { + char p = getchr(); + PF(start, p); + break; + } + case 's': { + char *p = getstr(); + PF(start, p); + break; + } + case 'd': + case 'i': { + char *f = mklong(start, convch); + long p = getlong(); + PF(f, p); + break; + } + case 'o': + case 'u': + case 'x': + case 'X': { + char *f = mklong(start, convch); + unsigned long p = getulong(); + PF(f, p); + break; + } + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': { + double p = getdouble(); + PF(start, p); + break; + } + default: + warnx ("%s: invalid directive", start); + return(1); + } + *(fmt + 1) = nextch; + break; + + case '\\': + fmt += print_escape(fmt); + break; + + default: + (void)putchar(*fmt); + break; + } + } + } while (gargv > argv && *gargv); + + return (rval); +} + + +/* + * Print SysV echo(1) style escape string + * Halts processing string and returns 1 if a \c escape is encountered. + */ +static int +print_escape_str(str) + const char *str; +{ + int value; + int c; + + while (*str) { + if (*str == '\\') { + str++; + /* + * %b string octal constants are not like those in C. + * They start with a \0, and are followed by 0, 1, 2, + * or 3 octal digits. + */ + if (*str == '0') { + str++; + for (c = 3, value = 0; c-- && isodigit(*str); str++) { + value <<= 3; + value += octtobin(*str); + } + (void)putchar(value); + str--; + } else if (*str == 'c') { + return 1; + } else { + str--; + str += print_escape(str); + } + } else { + (void)putchar(*str); + } + str++; + } + + return 0; +} + +/* + * Print "standard" escape characters + */ +static size_t +print_escape(str) + const char *str; +{ + const char *start = str; + int value; + int c; + + str++; + + switch (*str) { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + for (c = 3, value = 0; c-- && isodigit(*str); str++) { + value <<= 3; + value += octtobin(*str); + } + (void)putchar(value); + return str - start - 1; + /* NOTREACHED */ + + case 'x': + str++; + for (value = 0; isxdigit(*str); str++) { + value <<= 4; + value += hextobin(*str); + } + if (value > UCHAR_MAX) { + warnx ("escape sequence out of range for character"); + rval = 1; + } + (void)putchar (value); + return str - start - 1; + /* NOTREACHED */ + + case '\\': /* backslash */ + (void)putchar('\\'); + break; + + case '\'': /* single quote */ + (void)putchar('\''); + break; + + case '"': /* double quote */ + (void)putchar('"'); + break; + + case 'a': /* alert */ +#ifdef __STDC__ + (void)putchar('\a'); +#else + (void)putchar(007); +#endif + break; + + case 'b': /* backspace */ + (void)putchar('\b'); + break; + + case 'e': /* escape */ +#ifdef __GNUC__ + (void)putchar('\e'); +#else + (void)putchar(033); +#endif + break; + + case 'f': /* form-feed */ + (void)putchar('\f'); + break; + + case 'n': /* newline */ + (void)putchar('\n'); + break; + + case 'r': /* carriage-return */ + (void)putchar('\r'); + break; + + case 't': /* tab */ + (void)putchar('\t'); + break; + + case 'v': /* vertical-tab */ + (void)putchar('\v'); + break; + + default: + (void)putchar(*str); + warnx("unknown escape sequence `\\%c'", *str); + rval = 1; + break; + } + + return 1; +} + +static char * +mklong(str, ch) + const char *str; + char ch; +{ + static char copy[64]; + size_t len; + + len = strlen(str) + 2; + (void)memmove(copy, str, len - 3); + copy[len - 3] = 'l'; + copy[len - 2] = ch; + copy[len - 1] = '\0'; + return (copy); +} + +static int +getchr() +{ + if (!*gargv) + return ('\0'); + return ((int)**gargv++); +} + +static char * +getstr() +{ + if (!*gargv) + return (""); + return (*gargv++); +} + +static char *Number = "+-.0123456789"; +static int +getint() +{ + if (!*gargv) + return(0); + + if (strchr(Number, **gargv)) + return(atoi(*gargv++)); + + return 0; +} + +static long +getlong() +{ + long val; + char *ep; + + if (!*gargv) + return(0L); + + if (**gargv == '\"' || **gargv == '\'') + return (long) *((*gargv++)+1); + + errno = 0; + val = strtol (*gargv, &ep, 0); + check_conversion(*gargv++, ep); + return val; +} + +static unsigned long +getulong() +{ + unsigned long val; + char *ep; + + if (!*gargv) + return(0UL); + + if (**gargv == '\"' || **gargv == '\'') + return (unsigned long) *((*gargv++)+1); + + errno = 0; + val = strtoul (*gargv, &ep, 0); + check_conversion(*gargv++, ep); + return val; +} + +static double +getdouble() +{ + double val; + char *ep; + + if (!*gargv) + return(0.0); + + if (**gargv == '\"' || **gargv == '\'') + return (double) *((*gargv++)+1); + + errno = 0; + val = strtod (*gargv, &ep); + check_conversion(*gargv++, ep); + return val; +} + +static void +check_conversion(s, ep) + const char *s; + const char *ep; +{ + if (*ep) { + if (ep == s) + warnx ("%s: expected numeric value", s); + else + warnx ("%s: not completely converted", s); + rval = 1; + } else if (errno == ERANGE) { + warnx ("%s: %s", s, strerror(ERANGE)); + rval = 1; + } +} + +static void +usage() +{ + (void)fprintf(stderr, "usage: printf format [arg ...]\n"); +} diff --git a/pwd/Makefile b/pwd/Makefile new file mode 100644 index 0000000..377d638 --- /dev/null +++ b/pwd/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = pwd + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = pwd.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble pwd.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/pwd/Makefile.postamble b/pwd/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/pwd/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/pwd/Makefile.preamble b/pwd/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/pwd/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/pwd/PB.project b/pwd/PB.project new file mode 100644 index 0000000..c6850b7 --- /dev/null +++ b/pwd/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (pwd.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, pwd.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = pwd; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/pwd/pwd.1 b/pwd/pwd.1 new file mode 100644 index 0000000..8c443c7 --- /dev/null +++ b/pwd/pwd.1 @@ -0,0 +1,83 @@ +.\" $NetBSD: pwd.1,v 1.12 1997/09/14 08:51:38 lukem Exp $ +.\" +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)pwd.1 8.2 (Berkeley) 4/28/95 +.\" +.Dd November 2, 1998 +.Dt PWD 1 +.Os BSD 4 +.Sh NAME +.Nm pwd +.Nd return working directory name +.Sh SYNOPSIS +.Nm +.Op Fl LP +.Sh DESCRIPTION +.Nm +writes the absolute pathname of the current working directory to +the standard output. +.Pp +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Pp +The following options are available: +.Bl -tag -width indent +.It Fl L +Print the logical path to the current working directory, as defined +by the shell in the evironment variable PWD. +.It Fl P +Print the physical path to the current working directory, with symbolic +links in the path resolved. This is the default. +.El +.Sh STANDARDS +The +.Nm +utility is expected to be +.St -p1003.2 +compatible. +.Sh SEE ALSO +.Xr cd 1 , +.Xr csh 1 , +.Xr getcwd 3 +.Sh BUGS +In +.Xr csh 1 +the command +.Ic dirs +is always faster (although it can give a different answer in the rare case +that the current directory or a containing directory was moved after +the shell descended into it). diff --git a/pwd/pwd.c b/pwd/pwd.c new file mode 100644 index 0000000..bdd80bd --- /dev/null +++ b/pwd/pwd.c @@ -0,0 +1,160 @@ +/* $NetBSD: pwd.c,v 1.10 1998/07/28 05:31:26 mycroft Exp $ */ + +/* + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)pwd.c 8.3 (Berkeley) 4/1/94"; +#else +__RCSID("$NetBSD: pwd.c,v 1.10 1998/07/28 05:31:26 mycroft Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include + +char *getcwd_logical __P((char *, size_t)); +void usage __P((void)); +int main __P((int, char *[])); + +#ifdef __APPLE__ +char +*getcwd_physical(pt, size) + char *pt; + size_t size; +{ + unsetenv("PWD"); + return getcwd(pt, size); +} +#define getcwd getcwd_physical +#endif + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int ch; + int lFlag=0; + char *p = NULL; + + while ((ch = getopt(argc, argv, "LP")) != -1) + switch (ch) { + case 'L': + lFlag=1; + break; + case 'P': + lFlag=0; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 0) + usage(); + + if (lFlag) + p = getcwd_logical(NULL, 0); + else + p = getcwd(NULL, 0); + + if (p == NULL) err(1, "%s", ""); + + (void)printf("%s\n", p); + + exit(0); + /* NOTREACHED */ +} + +char * +getcwd_logical(pt, size) + char *pt; + size_t size; +{ + char *pwd; + size_t pwdlen; + dev_t dev; + ino_t ino; + struct stat s; + + /* Check $PWD -- if it's right, it's fast. */ + if ((pwd = getenv("PWD")) != NULL && pwd[0] == '/' && stat(pwd, &s) != -1) { + dev = s.st_dev; + ino = s.st_ino; + if (stat(".", &s) != -1 && dev == s.st_dev && ino == s.st_ino) { + pwdlen = strlen(pwd); + if (pt) { + if (!size) { + errno = EINVAL; + return (NULL); + } + if (pwdlen + 1 > size) { + errno = ERANGE; + return (NULL); + } + } else if ((pt = malloc(pwdlen + 1)) == NULL) { + errno = ENOMEM; + return (NULL); + } + memmove(pt, pwd, pwdlen); + pt[pwdlen] = '\0'; + return (pt); + } + } + + return (NULL); +} + +void +usage() +{ + (void)fprintf(stderr, "usage: pwd [-LP]\n"); + exit(1); + /* NOTREACHED */ +} diff --git a/renice/Makefile b/renice/Makefile new file mode 100644 index 0000000..8cd335f --- /dev/null +++ b/renice/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = renice + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = renice.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble renice.8 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/renice/Makefile.postamble b/renice/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/renice/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/renice/Makefile.preamble b/renice/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/renice/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/renice/PB.project b/renice/PB.project new file mode 100644 index 0000000..8b0d1bb --- /dev/null +++ b/renice/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (renice.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, renice.8); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = renice; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/renice/renice.8 b/renice/renice.8 new file mode 100644 index 0000000..ef9cb20 --- /dev/null +++ b/renice/renice.8 @@ -0,0 +1,135 @@ +.\" $NetBSD: renice.8,v 1.5 1997/10/19 14:01:33 lukem Exp $ +.\" +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)renice.8 8.1 (Berkeley) 6/9/93 +.\" $NetBSD: renice.8,v 1.5 1997/10/19 14:01:33 lukem Exp $ +.\" +.Dd June 9, 1993 +.Dt RENICE 8 +.Os BSD 4 +.Sh NAME +.Nm renice +.Nd alter priority of running processes +.Sh SYNOPSIS +.Nm +.Ar priority +.Oo +.Op Fl p +.Ar pid ... +.Oc +.Oo +.Op Fl g +.Ar pgrp ... +.Oc +.Oo +.Op Fl u +.Ar user ... +.Oc +.Sh DESCRIPTION +.Nm +alters the +scheduling priority of one or more running processes. +The following +.Ar who +parameters are interpreted as process ID's, process group +ID's, or user names. +.Nm "" Ns 'ing +a process group causes all processes in the process group +to have their scheduling priority altered. +.Nm "" Ns 'ing +a user causes all processes owned by the user to have +their scheduling priority altered. +By default, the processes to be affected are specified by +their process ID's. +.Pp +Options supported by +.Nm "" : +.Bl -tag -width Ds +.It Fl g +Force +.Ar who +parameters to be interpreted as process group ID's. +.It Fl u +Force the +.Ar who +parameters to be interpreted as user names. +.It Fl p +Resets the +.Ar who +interpretation to be (the default) process ID's. +.El +.Pp +For example, +.Bd -literal -offset +renice +1 987 -u daemon root -p 32 +.Ed +.Pp +would change the priority of process ID's 987 and 32, and +all processes owned by users daemon and root. +.Pp +Users other than the super-user may only alter the priority of +processes they own, +and can only monotonically increase their ``nice value'' +within the range 0 to +.Dv PRIO_MAX +(20). +(This prevents overriding administrative fiats.) +The super-user +may alter the priority of any process +and set the priority to any value in the range +.Dv PRIO_MIN +(\-20) +to +.Dv PRIO_MAX . +Useful priorities are: +20 (the affected processes will run only when nothing else +in the system wants to), +0 (the ``base'' scheduling priority), +anything negative (to make things go very fast). +.Sh FILES +.Bl -tag -width /etc/passwd -compact +.It Pa /etc/passwd +to map user names to user ID's +.El +.Sh SEE ALSO +.Xr nice 1 , +.Xr getpriority 2 , +.Xr setpriority 2 +.Sh BUGS +Non super-users can not increase scheduling priorities of their own processes, +even if they were the ones that decreased the priorities in the first place. +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.0 . diff --git a/renice/renice.c b/renice/renice.c new file mode 100644 index 0000000..ba4a00d --- /dev/null +++ b/renice/renice.c @@ -0,0 +1,135 @@ +/* $NetBSD: renice.c,v 1.5 1997/10/19 14:01:38 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +/*static char sccsid[] = "from: @(#)renice.c 8.1 (Berkeley) 6/9/93";*/ +__RCSID("$NetBSD: renice.c,v 1.5 1997/10/19 14:01:38 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include + +#include +#include +#include +#include + +int donice __P((int, int, int)); +int main __P((int, char **)); + +/* + * Change the priority (nice) of processes + * or groups of processes which are already + * running. + */ +int +main(argc, argv) + int argc; + char **argv; +{ + int which = PRIO_PROCESS; + int who = 0, prio, errs = 0; + + argc--, argv++; + if (argc < 2) { + fprintf(stderr, "usage: renice priority [ [ -p ] pids ] "); + fprintf(stderr, "[ [ -g ] pgrps ] [ [ -u ] users ]\n"); + exit(1); + } + prio = atoi(*argv); + argc--, argv++; + if (prio > PRIO_MAX) + prio = PRIO_MAX; + if (prio < PRIO_MIN) + prio = PRIO_MIN; + for (; argc > 0; argc--, argv++) { + if (strcmp(*argv, "-g") == 0) { + which = PRIO_PGRP; + continue; + } + if (strcmp(*argv, "-u") == 0) { + which = PRIO_USER; + continue; + } + if (strcmp(*argv, "-p") == 0) { + which = PRIO_PROCESS; + continue; + } + if (which == PRIO_USER) { + register struct passwd *pwd = getpwnam(*argv); + + if (pwd == NULL) { + warnx("%s: unknown user", *argv); + continue; + } + who = pwd->pw_uid; + } else { + who = atoi(*argv); + if (who < 0) { + warnx("%s: bad value", *argv); + continue; + } + } + errs += donice(which, who, prio); + } + exit(errs != 0); +} + +int +donice(which, who, prio) + int which, who, prio; +{ + int oldprio; + extern int errno; + + errno = 0, oldprio = getpriority(which, who); + if (oldprio == -1 && errno) { + warn("%d: getpriority", who); + return (1); + } + if (setpriority(which, who, prio) < 0) { + warn("%d: setpriority", who); + return (1); + } + printf("%d: old priority %d, new priority %d\n", who, oldprio, prio); + return (0); +} diff --git a/script/Makefile b/script/Makefile new file mode 100644 index 0000000..08d1d7d --- /dev/null +++ b/script/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = script + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = script.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble script.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/script/Makefile.postamble b/script/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/script/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/script/Makefile.preamble b/script/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/script/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/script/PB.project b/script/PB.project new file mode 100644 index 0000000..0adad9f --- /dev/null +++ b/script/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (script.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, script.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = script; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/script/script.1 b/script/script.1 new file mode 100644 index 0000000..485bf30 --- /dev/null +++ b/script/script.1 @@ -0,0 +1,126 @@ +.\" $NetBSD: script.1,v 1.4 1997/10/19 22:57:47 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)script.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt SCRIPT 1 +.Os BSD 4 +.Sh NAME +.Nm script +.Nd make typescript of terminal session +.Sh SYNOPSIS +.Nm +.Op Fl a +.Op Ar file +.Sh DESCRIPTION +.Nm +makes a typescript of everything printed on your terminal. +It is useful for students who need a hardcopy record of an interactive +session as proof of an assignment, as the typescript file +can be printed out later with +.Xr lpr 1 . +.Pp +If the argument +.Ar file +is given, +.Nm +saves all dialogue in +.Ar file . +If no file name is given, the typescript is saved in the file +.Pa typescript . +.Pp +Option: +.Bl -tag -width Ds +.It Fl a +Append the output to +.Ar file +or +.Pa typescript , +retaining the prior contents. +.El +.Pp +The script ends when the forked shell exits (a +.Em control-D +to exit +the Bourne shell +.Pf ( Xr sh 1 ) , +and +.Em exit , +.Em logout +or +.Em control-d +(if +.Em ignoreeof +is not set) for the +C-shell, +.Xr csh 1 ) . +.Pp +Certain interactive commands, such as +.Xr vi 1 , +create garbage in the typescript file. +.Nm +works best with commands that do not manipulate the +screen, the results are meant to emulate a hardcopy +terminal. +.Sh ENVIRONMENT +The following environment variable is utilized by +.Nm +: +.Bl -tag -width SHELL +.It Ev SHELL +If the variable +.Ev SHELL +exists, the shell forked by +.Nm +will be that shell. If +.Ev SHELL +is not set, the Bourne shell +is assumed. (Most shells set this variable automatically). +.El +.Sh SEE ALSO +.Xr csh 1 +(for the +.Em history +mechanism). +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . +.Sh BUGS +.Nm +places +.Sy everything +in the log file, including linefeeds and backspaces. +This is not what the naive user expects. diff --git a/script/script.c b/script/script.c new file mode 100644 index 0000000..dc980ce --- /dev/null +++ b/script/script.c @@ -0,0 +1,249 @@ +/* $NetBSD: script.c,v 1.6 1998/04/02 11:08:34 kleink Exp $ */ + +/* + * Copyright (c) 1980, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1980, 1992, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: script.c,v 1.6 1998/04/02 11:08:34 kleink Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +FILE *fscript; +int master, slave; +int child, subchild; +int outcc; +char *fname; + +struct termios tt; + +void done __P((void)); +void dooutput __P((void)); +void doshell __P((void)); +void fail __P((void)); +void finish __P((int)); +int main __P((int, char **)); +void scriptflush __P((int)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int cc; + struct termios rtt; + struct winsize win; + int aflg, ch; + char ibuf[BUFSIZ]; + + aflg = 0; + while ((ch = getopt(argc, argv, "a")) != -1) + switch(ch) { + case 'a': + aflg = 1; + break; + case '?': + default: + (void)fprintf(stderr, "usage: script [-a] [file]\n"); + exit(1); + } + argc -= optind; + argv += optind; + + if (argc > 0) + fname = argv[0]; + else + fname = "typescript"; + + if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) + err(1, "fopen %s", fname); + + (void)tcgetattr(STDIN_FILENO, &tt); + (void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win); + if (openpty(&master, &slave, NULL, &tt, &win) == -1) + err(1, "openpty"); + + (void)printf("Script started, output file is %s\n", fname); + rtt = tt; + cfmakeraw(&rtt); + rtt.c_lflag &= ~ECHO; + (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt); + + (void)signal(SIGCHLD, finish); + child = fork(); + if (child < 0) { + warn("fork"); + fail(); + } + if (child == 0) { + subchild = child = fork(); + if (child < 0) { + warn("fork"); + fail(); + } + if (child) + dooutput(); + else + doshell(); + } + + (void)fclose(fscript); + while ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0) + (void)write(master, ibuf, cc); + done(); + /* NOTREACHED */ + return (0); +} + +void +finish(signo) + int signo; +{ + int die, pid; + union wait status; + + die = 0; + while ((pid = wait3((int *)&status, WNOHANG, 0)) > 0) + if (pid == child) + die = 1; + + if (die) + done(); +} + +void +dooutput() +{ + struct itimerval value; + int cc; + time_t tvec; + char obuf[BUFSIZ]; + + (void)close(STDIN_FILENO); + tvec = time(NULL); + (void)fprintf(fscript, "Script started on %s", ctime(&tvec)); + + (void)signal(SIGALRM, scriptflush); + value.it_interval.tv_sec = SECSPERMIN / 2; + value.it_interval.tv_usec = 0; + value.it_value = value.it_interval; + (void)setitimer(ITIMER_REAL, &value, NULL); + for (;;) { + cc = read(master, obuf, sizeof (obuf)); + if (cc <= 0) + break; + (void)write(1, obuf, cc); + (void)fwrite(obuf, 1, cc, fscript); + outcc += cc; + } + done(); +} + +void +scriptflush(signo) + int signo; +{ + if (outcc) { + (void)fflush(fscript); + outcc = 0; + } +} + +void +doshell() +{ + char *shell; + + shell = getenv("SHELL"); + if (shell == NULL) + shell = _PATH_BSHELL; + + (void)close(master); + (void)fclose(fscript); + login_tty(slave); + execl(shell, shell, "-i", NULL); + warn("execl %s", shell); + fail(); +} + +void +fail() +{ + + (void)kill(0, SIGTERM); + done(); +} + +void +done() +{ + time_t tvec; + + if (subchild) { + tvec = time(NULL); + (void)fprintf(fscript,"\nScript done on %s", ctime(&tvec)); + (void)fclose(fscript); + (void)close(master); + } else { + (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt); + (void)printf("Script done, output file is %s\n", fname); + } + exit(0); +} diff --git a/shlock/Makefile b/shlock/Makefile new file mode 100644 index 0000000..fcfe3a9 --- /dev/null +++ b/shlock/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = shlock + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = shlock.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble shlock.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/shlock/Makefile.postamble b/shlock/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/shlock/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/shlock/Makefile.preamble b/shlock/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/shlock/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/shlock/PB.project b/shlock/PB.project new file mode 100644 index 0000000..ad0493f --- /dev/null +++ b/shlock/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (shlock.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, shlock.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = shlock; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/shlock/shlock.1 b/shlock/shlock.1 new file mode 100644 index 0000000..82b62d2 --- /dev/null +++ b/shlock/shlock.1 @@ -0,0 +1,122 @@ +.\" $NetBSD: shlock.1,v 1.2 1997/10/19 23:08:43 lukem Exp $ +.\" +.Dd June 29, 1997 +.Dt SHLOCK 1 +.Os +.Sh NAME +.Nm shlock +.Nd create or verify a lock file for shell scripts +.Sh SYNOPSIS +.Nm +.Fl f +.Ar lockfile +.Op Fl p Ar PID +.Op Fl u +.Op Fl v +.Sh DESCRIPTION +The +.Nm +command can create or verify a lock file on behalf of a shell or +other script program. +When it attempts to create a lock file, if one already exists, +.Nm +verifies that it is or is not valid. +If valid, +.Nm +will exit with a non-zero exit code. +If invalid, +.Nm +will remove the lock file, and +create a new one. +.Pp +.Nm +uses the +.Xr rename 2 +system call to make the final target lock file, which is an atomic +operation (i.e. "dot locking", so named for this mechanism's original +use for locking system mailboxes). +It puts the process ID ("PID") from the command line into the +requested lock file. +.Pp +.Nm +verifies that an extant lock file is still valid by +using +.Xr kill 2 +with a zero signal to check for the existence of the process that +holds the lock. +.Pp +The +.Fl f +argument with +.Ar lockfile +is always required. +.Pp +The +.Fl p +option with +.Ar PID +is given when the program is to create a lock file; when absent, +.Nm +will simply check for the validity of the lock file. +.Pp +The +.Fl u +option causes +.Nm +to read and write the PID as a binary pid_t, instead of as ASCII, +to be compatible with the locks created by UUCP. +.Pp +The +.Fl v +option causes +.Nm +to be verbose about what it is doing. +.Sh RETURN VALUES +A zero exit code indicates a valid lock file. +.Sh EXAMPLES +.Ss BOURNE SHELL +.Bd -literal +#!/bin/sh +lckfile=/tmp/foo.lock +if shlock -f ${lckfile} -p $$ +then +# do what required the lock + rm ${lckfile} +else + echo Lock ${lckfile} already held by `cat ${lckfile}` +fi +.Ed +.Ss C SHELL +.Bd -literal +#!/bin/csh -f +set lckfile=/tmp/foo.lock +shlock -f ${lckfile} -p $$ +if ($status == 0) then +# do what required the lock + rm ${lckfile} +else + echo Lock ${lckfile} already held by `cat ${lckfile}` +endif +.Ed + +.Pp +The examples assume that the filesystem where the lock file is to +be created is writeable by the user, and has space available. +.Sh HISTORY +.Nm +was written for the first Network News Transfer Protocol (NNTP) +software distribution, released in March 1986. +The algorithm was suggested by Peter Honeyman, +from work he did on HoneyDanBer UUCP. +.Sh AUTHOR +Erik E. Fair +.Sh BUGS +Does not work on NFS or other network filesystem on different +systems because the disparate systems have disjoint PID spaces. +.Pp +Cannot handle the case where a lock file was not deleted, the +process that created it has exited, and the system has created a +new process with the same PID as in the dead lock file. +The lock file will appear to be valid even though the process is +unrelated to the one that created the lock in the first place. +Always remove your lock files after you're done. diff --git a/shlock/shlock.c b/shlock/shlock.c new file mode 100644 index 0000000..862e4b7 --- /dev/null +++ b/shlock/shlock.c @@ -0,0 +1,344 @@ +/* $NetBSD: shlock.c,v 1.3 1998/01/09 08:06:11 perry Exp $ */ + +/* +** Program to produce reliable locks for shell scripts. +** Algorithm suggested by Peter Honeyman, January 1984, +** in connection with HoneyDanBer UUCP. +** +** I tried extending this to handle shared locks in November 1987, +** and ran into to some fundamental problems: +** +** Neither 4.3 BSD nor System V have an open(2) with locking, +** so that you can open a file and have it locked as soon as +** it's real; you have to make two system calls, and there's +** a race... +** +** When removing dead process id's from a list in a file, +** you need to truncate the file (you don't want to create a +** new one; see above); unfortunately for the portability of +** this program, only 4.3 BSD has ftruncate(2). +** +** Erik E. Fair , November 8, 1987 +** +** Extensions for UUCP style locks (i.e. pid is an int in the file, +** rather than an ASCII string). Also fix long standing bug with +** full file systems and temporary files. +** +** Erik E. Fair , November 12, 1989 +** +** ANSIfy the code somewhat to make gcc -Wall happy with the code. +** Submit to NetBSD +** +** Erik E. Fair , May 20, 1997 +*/ + +#include +#include +#include /* Needed on hpux */ +#include +#include +#include +#include +#include +#include + +#define LOCK_SET 0 +#define LOCK_FAIL 1 + +#define LOCK_GOOD 0 +#define LOCK_BAD 1 + +#define FAIL (-1) + +#define TRUE 1 +#define FALSE 0 + +int Debug = FALSE; +char *Pname; +char *USAGE = "%s: USAGE: shlock -f file -p pid [-d][-u]\n"; +char *E_unlk = "%s: unlink(%s): %s\n"; +char *E_open = "%s: open(%s): %s\n"; + +#define dprintf if (Debug) printf + +/* +** Prototypes to make the ANSI compilers happy +** Didn't lint used to do type and argument checking? +** (and wasn't that sufficient?) +*/ + +#ifdef __STDC__ +/* the following is in case you need to make the prototypes go away. */ +#define _P(x) x + +char *xtmpfile _P((char *, pid_t, int)); +int p_exists _P((pid_t)); +int cklock _P((char *, int)); +int mklock _P((char *, pid_t, int)); +void bad_usage _P((void)); +int main _P((int, char **)); +#endif /* __STDC__ */ + +/* +** Create a temporary file, all ready to lock with. +** The file arg is so we get the filename right, if he +** gave us a full path, instead of using the current directory +** which might not be in the same filesystem. +*/ +char * +xtmpfile(file, pid, uucpstyle) +char *file; +pid_t pid; +int uucpstyle; +{ + int fd; + int len; + char *cp, buf[BUFSIZ]; + static char tempname[BUFSIZ]; + + sprintf(buf, "shlock%d", getpid()); + if ((cp = strrchr(strcpy(tempname, file), '/')) != (char *)NULL) { + *++cp = '\0'; + (void) strcat(tempname, buf); + } else + (void) strcpy(tempname, buf); + dprintf("%s: temporary filename: %s\n", Pname, tempname); + + sprintf(buf, "%d\n", pid); + len = strlen(buf); +openloop: + if ((fd = open(tempname, O_RDWR|O_CREAT|O_EXCL, 0644)) < 0) { + switch(errno) { + case EEXIST: + dprintf("%s: file %s exists already.\n", + Pname, tempname); + if (unlink(tempname) < 0) { + fprintf(stderr, E_unlk, + Pname, tempname, strerror(errno)); + return((char *)NULL); + } + /* + ** Further profanity + */ + goto openloop; + default: + fprintf(stderr, E_open, + Pname, tempname, strerror(errno)); + return((char *)NULL); + } + } + + /* + ** Write the PID into the temporary file before attempting to link + ** to the actual lock file. That way we have a valid lock the instant + ** the link succeeds. + */ + if (uucpstyle ? + (write(fd, &pid, sizeof(pid)) != sizeof(pid)) : + (write(fd, buf, len) < 0)) + { + fprintf(stderr, "%s: write(%s,%d): %s\n", + Pname, tempname, pid, strerror(errno)); + (void) close(fd); + if (unlink(tempname) < 0) { + fprintf(stderr, E_unlk, + Pname, tempname, strerror(errno)); + } + return((char *)NULL); + } + (void) close(fd); + return(tempname); +} + +/* +** Does the PID exist? +** Send null signal to find out. +*/ +int +p_exists(pid) +pid_t pid; +{ + dprintf("%s: process %d is ", Pname, pid); + if (pid <= 0) { + dprintf("invalid\n"); + return(FALSE); + } + if (kill(pid, 0) < 0) { + switch(errno) { + case ESRCH: + dprintf("dead\n"); + return(FALSE); /* pid does not exist */ + case EPERM: + dprintf("alive\n"); + return(TRUE); /* pid exists */ + default: + dprintf("state unknown: %s\n", strerror(errno)); + return(TRUE); /* be conservative */ + } + } + dprintf("alive\n"); + return(TRUE); /* pid exists */ +} + +/* +** Check the validity of an existing lock file. +** +** Read the PID out of the lock +** Send a null signal to determine whether that PID still exists +** Existence (or not) determines the validity of the lock. +** +** Two bigs wins to this algorithm: +** +** o Locks do not survive crashes of either the system or the +** application by any appreciable period of time. +** +** o No clean up to do if the system or application crashes. +** +*/ +int +cklock(file, uucpstyle) +char *file; +int uucpstyle; +{ + int fd = open(file, O_RDONLY); + ssize_t len; + pid_t pid; + char buf[BUFSIZ]; + + dprintf("%s: checking extant lock <%s>\n", Pname, file); + if (fd < 0) { + if (errno != ENOENT) + fprintf(stderr, E_open, Pname, file, strerror(errno)); + return(TRUE); /* might or might not; conservatism */ + } + + if (uucpstyle ? + ((len = read(fd, &pid, sizeof(pid))) != sizeof(pid)) : + ((len = read(fd, buf, sizeof(buf))) <= 0)) + { + close(fd); + dprintf("%s: lock file format error\n", Pname); + return(FALSE); + } + close(fd); + buf[len + 1] = '\0'; + return(p_exists(uucpstyle ? pid : atoi(buf))); +} + +int +mklock(file, pid, uucpstyle) +char *file; +pid_t pid; +int uucpstyle; +{ + char *tmp; + int retcode = FALSE; + + dprintf("%s: trying lock <%s> for process %d\n", Pname, file, pid); + if ((tmp = xtmpfile(file, pid, uucpstyle)) == (char *)NULL) + return(FALSE); + +linkloop: + if (link(tmp, file) < 0) { + switch(errno) { + case EEXIST: + dprintf("%s: lock <%s> already exists\n", Pname, file); + if (cklock(file, uucpstyle)) { + dprintf("%s: extant lock is valid\n", Pname); + break; + } else { + dprintf("%s: lock is invalid, removing\n", + Pname); + if (unlink(file) < 0) { + fprintf(stderr, E_unlk, + Pname, file, strerror(errno)); + break; + } + } + /* + ** I hereby profane the god of structured programming, + ** Edsgar Dijkstra + */ + goto linkloop; + default: + fprintf(stderr, "%s: link(%s, %s): %s\n", + Pname, tmp, file, strerror(errno)); + break; + } + } else { + dprintf("%s: got lock <%s>\n", Pname, file); + retcode = TRUE; + } + if (unlink(tmp) < 0) { + fprintf(stderr, E_unlk, Pname, tmp, strerror(errno)); + } + return(retcode); +} + +void +bad_usage() +{ + fprintf(stderr, USAGE, Pname); + exit(LOCK_FAIL); +} + +int +main(ac, av) +int ac; +char *av[]; +{ + int x; + char *file = (char *)NULL; + pid_t pid = 0; + int uucpstyle = FALSE; /* indicating UUCP style locks */ + int only_check = TRUE; /* don't make a lock */ + + Pname = ((Pname = strrchr(av[0], '/')) ? Pname + 1 : av[0]); + + for(x = 1; x < ac; x++) { + if (av[x][0] == '-') { + switch(av[x][1]) { + case 'u': + uucpstyle = TRUE; + break; + case 'd': + Debug = TRUE; + break; + case 'p': + if (strlen(av[x]) > 2) { + pid = atoi(&av[x][2]); + } else { + if (++x >= ac) { + bad_usage(); + } + pid = atoi(av[x]); + } + only_check = FALSE; /* wants one */ + break; + case 'f': + if (strlen(av[x]) > 2) { + file = &av[x][2]; + } else { + if (++x >= ac) { + bad_usage(); + } + file = av[x]; + } + break; + default: + fprintf(stderr, USAGE, Pname); + exit(LOCK_FAIL); + } + } + } + + if (file == (char *)NULL || (!only_check && pid <= 0)) { + bad_usage(); + } + + if (only_check) { + exit(cklock(file, uucpstyle) ? LOCK_GOOD : LOCK_BAD); + } + + exit(mklock(file, pid, uucpstyle) ? LOCK_SET : LOCK_FAIL); +} diff --git a/sleep/Makefile b/sleep/Makefile new file mode 100644 index 0000000..0f6ca2a --- /dev/null +++ b/sleep/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = sleep + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = sleep.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble sleep.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/sleep/Makefile.postamble b/sleep/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/sleep/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/sleep/Makefile.preamble b/sleep/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/sleep/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/sleep/PB.project b/sleep/PB.project new file mode 100644 index 0000000..4d7fea8 --- /dev/null +++ b/sleep/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (sleep.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, sleep.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = sleep; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/sleep/sleep.1 b/sleep/sleep.1 new file mode 100644 index 0000000..8815eaa --- /dev/null +++ b/sleep/sleep.1 @@ -0,0 +1,124 @@ +.\" $NetBSD: sleep.1,v 1.11 1997/09/14 07:31:56 lukem Exp $ +.\" +.\" Copyright (c) 1990, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)sleep.1 8.3 (Berkeley) 4/18/94 +.\" +.Dd April 18, 1994 +.Dt SLEEP 1 +.Os +.Sh NAME +.Nm sleep +.Nd suspend execution for an interval of time +.Sh SYNOPSIS +.Nm +.Ar seconds +.Sh DESCRIPTION +The +.Nm +utility +suspends execution for a minimum of +.Ar seconds . +It is usually used to schedule the execution of other commands (see +.Sx EXAMPLES +below). +.Pp +The +.Nm +utility exits with one of the following values: +.Bl -tag -width flag +.It Li \&0 +On successful completion, or if the signal +.Dv SIGALRM +was received. +.It Li \&>\&0 +An error occurred. +.El +.Pp +Note: The +.Nx +.Nm +command will accept and honor a non-integer number of specified +seconds. This is a non-portable extension, and its use will nearly +guarantee that a shell script will not execute properly on another +system. +.Sh EXAMPLES +To schedule the execution of a command for +.Va x +number seconds later: +.Pp +.Dl (sleep 1800; sh command_file >& errors)& +.Pp +This incantation would wait a half hour before +running the script command_file. (See the +.Xr at 1 +utility.) +.Pp +To reiteratively run a command (with the +.Xr csh 1 ) : +.Pp +.Bd -literal -offset indent -compact +while (1) + if (! -r zzz.rawdata) then + sleep 300 + else + foreach i (`ls *.rawdata`) + sleep 70 + awk -f collapse_data $i >> results + end + break + endif +end +.Ed +.Pp +The scenario for a script such as this might be: a program currently +running is taking longer than expected to process a series of +files, and it would be nice to have +another program start processing the files created by the first +program as soon as it is finished (when zzz.rawdata is created). +The script checks every five minutes for the file zzz.rawdata, +when the file is found, then another portion processing +is done courteously by sleeping for 70 seconds in between each +awk job. +.Sh SEE ALSO +.Xr nanosleep 2 , +.Xr sleep 3 , +.Xr at 1 +.Sh STANDARDS +The +.Nm +command is expected to be +.St -p1003.2 +compatible. diff --git a/sleep/sleep.c b/sleep/sleep.c new file mode 100644 index 0000000..7f0203a --- /dev/null +++ b/sleep/sleep.c @@ -0,0 +1,154 @@ +/* $NetBSD: sleep.c,v 1.15 1998/07/28 11:41:58 mycroft Exp $ */ + +/* + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)sleep.c 8.3 (Berkeley) 4/2/94"; +#else +__RCSID("$NetBSD: sleep.c,v 1.15 1998/07/28 11:41:58 mycroft Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include + +void usage __P((void)); +void alarmhandle __P((int)); +int main __P((int, char *[])); + +int +main(argc, argv) + int argc; + char *argv[]; +{ +#ifndef __APPLE__ + char *arg, *temp; + double val, ival, fval; + struct timespec ntime; + int fracflag; +#else + int secs; +#endif + int ch; + + (void)setlocale(LC_ALL, ""); + + (void)signal(SIGALRM, alarmhandle); + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc != 1) + usage(); + +#ifdef __APPLE__ + if ((secs = atoi(*argv)) > 0) + (void)sleep(secs); +#else + /* + * Okay, why not just use atof for everything? Why bother + * checking if there is a fraction in use? Because the old + * sleep handled the full range of integers, that's why, and a + * double can't handle a large long. This is fairly useless + * given how large a number a double can hold on most + * machines, but now we won't ever have trouble. If you want + * 1000000000.9 seconds of sleep, well, that's your + * problem. Why use an isdigit() check instead of checking for + * a period? Because doing it this way means locales will be + * handled transparently by the atof code. + */ + fracflag = 0; + arg = *argv; + for (temp = arg; *temp != '\0'; temp++) + if (!isdigit(*temp)) + fracflag++; + + if (fracflag) { + val = atof(arg); + if (val <= 0) + exit(0); + ival = floor(val); + fval = (1000000000 * (val-ival)); + ntime.tv_sec = ival; + ntime.tv_nsec = fval; + } + else{ + ntime.tv_sec = atol(arg); + if (ntime.tv_sec <= 0) + exit(0); + ntime.tv_nsec = 0; + } + + (void)nanosleep(&ntime, NULL); +#endif + + exit(0); + /* NOTREACHED */ +} + +void +usage() +{ + (void)fputs("usage: sleep seconds\n", stderr); + exit(1); + /* NOTREACHED */ +} + +/* ARGSUSED */ +void +alarmhandle(i) + int i; +{ + _exit(0); + /* NOTREACHED */ +} diff --git a/su/Makefile b/su/Makefile new file mode 100644 index 0000000..06864a4 --- /dev/null +++ b/su/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = su + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = su.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble su.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/su/Makefile.postamble b/su/Makefile.postamble new file mode 100644 index 0000000..e5df476 --- /dev/null +++ b/su/Makefile.postamble @@ -0,0 +1,5 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common + +INSTALL_AS_USER = root +INSTALL_AS_GROUP = wheel +INSTALL_PERMISSIONS = 4555 diff --git a/su/Makefile.preamble b/su/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/su/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/su/PB.project b/su/PB.project new file mode 100644 index 0000000..369af31 --- /dev/null +++ b/su/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (su.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, su.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = su; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/su/su.1 b/su/su.1 new file mode 100644 index 0000000..8ed4b4c --- /dev/null +++ b/su/su.1 @@ -0,0 +1,186 @@ +.\" Copyright (c) 1988, 1990, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)su.1 8.2 (Berkeley) 4/18/94 +.\" $NetBSD: su.1,v 1.14 1997/10/19 23:31:52 lukem Exp $ +.\" +.Dd April 18, 1994 +.Dt SU 1 +.Os +.Sh NAME +.Nm su +.Nd substitute user identity +.Sh SYNOPSIS +.Nm +.Op Fl Kflm +.Op Ar login Op Ar "shell arguments" +.Sh DESCRIPTION +.Nm +requests the Kerberos password for +.Ar login +(or for +.Dq Ar login Ns .root , +if no login is provided), and switches to +that user and group ID after obtaining a Kerberos ticket granting ticket. +A shell is then executed, and any additional +.Ar "shell arguments" +after the login name +are passed to the shell. +.Nm +will resort to the local password file to find the password for +.Ar login +if there is a Kerberos error. +If +.Nm +is executed by root, no password is requested and a shell +with the appropriate user ID is executed; no additional Kerberos tickets +are obtained. +.Pp +Alternatively, if the user enters the password "s/key", authentication +will use the S/Key one-time password system as described in +.Xr skey 1 . +S/Key is a Trademark of Bellcore. +.Pp +By default, the environment is unmodified with the exception of +.Ev USER , +.Ev HOME , +and +.Ev SHELL . +.Ev HOME +and +.Ev SHELL +are set to the target login's default values. +.Ev USER +is set to the target login, unless the target login has a user ID of 0, +in which case it is unmodified. +The invoked shell is the target login's. +This is the traditional behavior of +.Nm su . +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl K +Do not attempt to use Kerberos to authenticate the user. +.It Fl f +If the invoked shell is +.Xr csh 1 , +this option prevents it from reading the +.Dq Pa .cshrc +file. +.It Fl l +Simulate a full login. +The environment is discarded except for +.Ev HOME , +.Ev SHELL , +.Ev PATH , +.Ev TERM , +and +.Ev USER . +.Ev HOME +and +.Ev SHELL +are modified as above. +.Ev USER +is set to the target login. +.Ev PATH +is set to +.Dq Pa /bin:/usr/bin . +.Ev TERM +is imported from your current environment. +The invoked shell is the target login's, and +.Nm +will change directory to the target login's home directory. +.It Fl m +Leave the environment unmodified. +The invoked shell is your login shell, and no directory changes are made. +As a security precaution, if the target user's shell is a non-standard +shell (as defined by +.Xr getusershell 3 ) +and the caller's real uid is +non-zero, +.Nm +will fail. +.El +.Pp +The +.Fl l +and +.Fl m +options are mutually exclusive; the last one specified +overrides any previous ones. +.Pp +Only users in group +.Dq wheel +(normally gid 0), +as listed in +.Pa /etc/group , +can +.Nm +to +.Dq root . +.Pp +By default (unless the prompt is reset by a startup file) the super-user +prompt is set to +.Dq Sy \&# +to remind one of its awesome power. +.Sh SEE ALSO +.Xr csh 1 , +.Xr login 1 , +.Xr sh 1 , +.Xr skey 1 , +.Xr kinit 1 , +.Xr kerberos 1 , +.Xr passwd 5 , +.Xr group 5 , +.Xr environ 7 +.Sh ENVIRONMENT +Environment variables used by +.Nm +: +.Bl -tag -width "HOME" +.It Ev HOME +Default home directory of real user ID unless modified as +specified above. +.It Ev PATH +Default search path of real user ID unless modified as specified above. +.It Ev TERM +Provides terminal type which may be retained for the substituted +user ID. +.It Ev USER +The user ID is always the effective ID (the target user ID) after an +.Nm +unless the user ID is 0 (root). +.El +.Sh HISTORY +A +.Nm +command appeared in +.At v7 . diff --git a/su/su.c b/su/su.c new file mode 100644 index 0000000..750d02b --- /dev/null +++ b/su/su.c @@ -0,0 +1,504 @@ +/* $NetBSD: su.c,v 1.26 1998/08/25 20:59:40 ross Exp $ */ + +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( + "@(#) Copyright (c) 1988 The Regents of the University of California.\n\ + All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)su.c 8.3 (Berkeley) 4/2/94";*/ +#else +__RCSID("$NetBSD: su.c,v 1.26 1998/08/25 20:59:40 ross Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef SKEY +#include +#endif +#include +#include +#include +#include +#include +#include + +#ifdef KERBEROS +#include +#include +#include + +#define ARGSTR "-Kflm" + +int use_kerberos = 1; + +static int kerberos __P((char *, char *, int)); +static int koktologin __P((char *, char *, char *)); + +#else +#define ARGSTR "-flm" +#endif + +#ifndef SUGROUP +#define SUGROUP "wheel" +#endif + + +int main __P((int, char **)); + +static int chshell __P((const char *)); +static char *ontty __P((void)); + + +int +main(argc, argv) + int argc; + char **argv; +{ + extern char *__progname; + extern char **environ; + struct passwd *pwd; + char *p; + struct timeval tp; + uid_t ruid; + gid_t usergid; + int asme, ch, asthem, fastlogin, prio; + enum { UNSET, YES, NO } iscsh = UNSET; + char *user, *shell, *avshell, *username, *cleanenv[10], **np; + char shellbuf[MAXPATHLEN], avshellbuf[MAXPATHLEN]; + + asme = asthem = fastlogin = 0; + shell = NULL; + while ((ch = getopt(argc, argv, ARGSTR)) != -1) + switch((char)ch) { +#ifdef KERBEROS + case 'K': + use_kerberos = 0; + break; +#endif + case 'f': + fastlogin = 1; + break; + case '-': + case 'l': + asme = 0; + asthem = 1; + break; + case 'm': + asme = 1; + asthem = 0; + break; + case '?': + default: + (void)fprintf(stderr, + "Usage: %s [%s] [login [shell arguments]]\n", + __progname, ARGSTR); + exit(1); + } + argv += optind; + + errno = 0; + prio = getpriority(PRIO_PROCESS, 0); + if (errno) + prio = 0; + (void)setpriority(PRIO_PROCESS, 0, -2); + openlog("su", LOG_CONS, 0); + + /* get current login name and shell */ + ruid = getuid(); + username = getlogin(); + if (username == NULL || (pwd = getpwnam(username)) == NULL || + pwd->pw_uid != ruid) + pwd = getpwuid(ruid); + if (pwd == NULL) + errx(1, "who are you?"); + username = strdup(pwd->pw_name); + usergid = pwd->pw_gid; + if (username == NULL) + err(1, "strdup"); + + if (asme) { + if (pwd->pw_shell && *pwd->pw_shell) { + shell = strncpy(shellbuf, pwd->pw_shell, + sizeof(shellbuf) - 1); + shellbuf[sizeof(shellbuf) - 1] = '\0'; + } else { + shell = _PATH_BSHELL; + iscsh = NO; + } + } + /* get target login information, default to root */ + user = *argv ? *argv : "root"; + np = *argv ? argv : argv-1; + + if ((pwd = getpwnam(user)) == NULL) + errx(1, "unknown login %s", user); + + if (ruid +#ifdef KERBEROS + && (!use_kerberos || kerberos(username, user, pwd->pw_uid)) +#endif + ) { + gid_t groups[NGROUPS_MAX]; + int numgroups; + + /* + * Only allow those in group SUGROUP to su to root. + */ + if (pwd->pw_uid == 0 && + (initgroups(username, usergid) == 0) && + ((numgroups = getgroups(NGROUPS_MAX, groups)) > 0)) { + int i; + int wheel = 0; + gid_t wheelgid = 0; + struct group *wheelgroup; + + if ((wheelgroup = getgrnam(SUGROUP)) != NULL) { + wheelgid = wheelgroup->gr_gid; + + for (i = 0; i < numgroups; i++) { + if (groups[i] == wheelgid) { + wheel = 1; + break; + } + } + } else { + /* If we can't get the gid for SUGROUP, then let anyone su */ + warnx("unknown secondary group %s; anyone can su %s.", SUGROUP, user); + wheel = 1; + } + + if (!wheel) + errx(1, + "you are not listed in the correct secondary group (%s) to su %s.", + SUGROUP, user); + } + + /* if target requires a password, verify it */ + if (*pwd->pw_passwd) { + p = getpass("Password:"); +#ifdef SKEY + if (strcasecmp(p, "s/key") == 0) { + if (skey_haskey(user)) + errx(1, "Sorry, you have no s/key."); + else { + if (skey_authenticate(user)) { + goto badlogin; + } + } + + } else +#endif + if (strcmp(pwd->pw_passwd, crypt(p, pwd->pw_passwd))) { +#ifdef SKEY +badlogin: +#endif + fprintf(stderr, "Sorry\n"); + syslog(LOG_AUTH|LOG_WARNING, + "BAD SU %s to %s%s", username, + user, ontty()); + exit(1); + } + } + } + + if (asme) { + /* if asme and non-standard target shell, must be root */ + if (!chshell(pwd->pw_shell) && ruid) + errx(1,"permission denied (shell)."); + } else if (pwd->pw_shell && *pwd->pw_shell) { + shell = pwd->pw_shell; + iscsh = UNSET; + } else { + shell = _PATH_BSHELL; + iscsh = NO; + } + + if ((p = strrchr(shell, '/')) != NULL) + avshell = p+1; + else + avshell = shell; + + /* if we're forking a csh, we want to slightly muck the args */ + if (iscsh == UNSET) + iscsh = strstr(avshell, "csh") ? YES : NO; + + /* set permissions */ + if (setgid(pwd->pw_gid) < 0) + err(1, "setgid"); + if (initgroups(user, pwd->pw_gid)) + errx(1, "initgroups failed"); + if (setuid(pwd->pw_uid) < 0) + err(1, "setuid"); + + if (!asme) { + if (asthem) { + p = getenv("TERM"); + cleanenv[0] = NULL; + environ = cleanenv; + (void)setenv("PATH", _PATH_DEFPATH, 1); + if (p) + (void)setenv("TERM", p, 1); + if (chdir(pwd->pw_dir) < 0) + errx(1, "no directory"); + } + if (asthem || pwd->pw_uid) + (void)setenv("USER", pwd->pw_name, 1); + (void)setenv("HOME", pwd->pw_dir, 1); + (void)setenv("SHELL", shell, 1); + } + + if (iscsh == YES) { + if (fastlogin) + *np-- = "-f"; + if (asme) + *np-- = "-m"; + } + + if (asthem) { + avshellbuf[0] = '-'; + (void)strncpy(avshellbuf+1, avshell, sizeof(avshellbuf) - 2); + avshell = avshellbuf; + } else if (iscsh == YES) { + /* csh strips the first character... */ + avshellbuf[0] = '_'; + (void)strncpy(avshellbuf+1, avshell, sizeof(avshellbuf) - 2); + avshell = avshellbuf; + } + *np = avshell; + + if (pwd->pw_change || pwd->pw_expire) + (void)gettimeofday(&tp, (struct timezone *)NULL); + if (pwd->pw_change) { + if (tp.tv_sec >= pwd->pw_change) { + (void)printf("%s -- %s's password has expired.\n", + (ruid ? "Sorry" : "Note"), user); + if (ruid != 0) + exit(1); + } else if (pwd->pw_change - tp.tv_sec < + _PASSWORD_WARNDAYS * SECSPERDAY) + (void)printf("Warning: %s's password expires on %s", + user, ctime(&pwd->pw_change)); + } + if (pwd->pw_expire) { + if (tp.tv_sec >= pwd->pw_expire) { + (void)printf("%s -- %s's account has expired.\n", + (ruid ? "Sorry" : "Note"), user); + if (ruid != 0) + exit(1); + } else if (pwd->pw_expire - tp.tv_sec < + _PASSWORD_WARNDAYS * SECSPERDAY) + (void)printf("Warning: %s's account expires on %s", + user, ctime(&pwd->pw_expire)); + } + if (ruid != 0) + syslog(LOG_NOTICE|LOG_AUTH, "%s to %s%s", + username, user, ontty()); + + (void)setpriority(PRIO_PROCESS, 0, prio); + + execv(shell, np); + err(1, "%s", shell); + /* NOTREACHED */ +} + +static int +chshell(sh) + const char *sh; +{ + const char *cp; + + while ((cp = getusershell()) != NULL) + if (!strcmp(cp, sh)) + return (1); + return (0); +} + +static char * +ontty() +{ + char *p; + static char buf[MAXPATHLEN + 4]; + + buf[0] = 0; + if ((p = ttyname(STDERR_FILENO)) != NULL) + (void)snprintf(buf, sizeof buf, " on %s", p); + return (buf); +} + +#ifdef KERBEROS +static int +kerberos(username, user, uid) + char *username, *user; + int uid; +{ + KTEXT_ST ticket; + AUTH_DAT authdata; + struct hostent *hp; + int kerno; + u_long faddr; + char lrealm[REALM_SZ], krbtkfile[MAXPATHLEN]; + char hostname[MAXHOSTNAMELEN + 1], savehost[MAXHOSTNAMELEN + 1]; + + if (krb_get_lrealm(lrealm, 1) != KSUCCESS) + return (1); + if (koktologin(username, lrealm, user) && !uid) { + warnx("kerberos: not in %s's ACL.", user); + return (1); + } + (void)(void)snprintf(krbtkfile, sizeof krbtkfile, "%s_%s_%d", TKT_ROOT, + user, getuid()); + + (void)setenv("KRBTKFILE", krbtkfile, 1); + (void)krb_set_tkt_string(krbtkfile); + /* + * Set real as well as effective ID to 0 for the moment, + * to make the kerberos library do the right thing. + */ + if (setuid(0) < 0) { + warn("setuid"); + return (1); + } + + /* + * Little trick here -- if we are su'ing to root, + * we need to get a ticket for "xxx.root", where xxx represents + * the name of the person su'ing. Otherwise (non-root case), + * we need to get a ticket for "yyy.", where yyy represents + * the name of the person being su'd to, and the instance is null + * + * We should have a way to set the ticket lifetime, + * with a system default for root. + */ + kerno = krb_get_pw_in_tkt((uid == 0 ? username : user), + (uid == 0 ? "root" : ""), lrealm, + "krbtgt", lrealm, DEFAULT_TKT_LIFE, 0); + + if (kerno != KSUCCESS) { + if (kerno == KDC_PR_UNKNOWN) { + warnx("kerberos: principal unknown: %s.%s@%s", + (uid == 0 ? username : user), + (uid == 0 ? "root" : ""), lrealm); + return (1); + } + warnx("kerberos: unable to su: %s", krb_err_txt[kerno]); + syslog(LOG_NOTICE|LOG_AUTH, + "BAD Kerberos SU: %s to %s%s: %s", + username, user, ontty(), krb_err_txt[kerno]); + return (1); + } + + if (chown(krbtkfile, uid, -1) < 0) { + warn("chown"); + (void)unlink(krbtkfile); + return (1); + } + + (void)setpriority(PRIO_PROCESS, 0, -2); + + if (gethostname(hostname, sizeof(hostname)) == -1) { + warn("gethostname"); + dest_tkt(); + return (1); + } + hostname[sizeof(hostname) - 1] = '\0'; + + (void)strncpy(savehost, krb_get_phost(hostname), sizeof(savehost)); + savehost[sizeof(savehost) - 1] = '\0'; + + kerno = krb_mk_req(&ticket, "rcmd", savehost, lrealm, 33); + + if (kerno == KDC_PR_UNKNOWN) { + warnx("Warning: TGT not verified."); + syslog(LOG_NOTICE|LOG_AUTH, + "%s to %s%s, TGT not verified (%s); %s.%s not registered?", + username, user, ontty(), krb_err_txt[kerno], + "rcmd", savehost); + } else if (kerno != KSUCCESS) { + warnx("Unable to use TGT: %s", krb_err_txt[kerno]); + syslog(LOG_NOTICE|LOG_AUTH, "failed su: %s to %s%s: %s", + username, user, ontty(), krb_err_txt[kerno]); + dest_tkt(); + return (1); + } else { + if (!(hp = gethostbyname(hostname))) { + warnx("can't get addr of %s", hostname); + dest_tkt(); + return (1); + } + memmove((char *)&faddr, (char *)hp->h_addr, sizeof(faddr)); + + if ((kerno = krb_rd_req(&ticket, "rcmd", savehost, faddr, + &authdata, "")) != KSUCCESS) { + warnx("kerberos: unable to verify rcmd ticket: %s\n", + krb_err_txt[kerno]); + syslog(LOG_NOTICE|LOG_AUTH, + "failed su: %s to %s%s: %s", username, + user, ontty(), krb_err_txt[kerno]); + dest_tkt(); + return (1); + } + } + return (0); +} + +static int +koktologin(name, realm, toname) + char *name, *realm, *toname; +{ + AUTH_DAT *kdata; + AUTH_DAT kdata_st; + + kdata = &kdata_st; + memset((char *)kdata, 0, sizeof(*kdata)); + (void)strncpy(kdata->pname, name, sizeof(kdata->pname) - 1); + (void)strncpy(kdata->pinst, + ((strcmp(toname, "root") == 0) ? "root" : ""), sizeof(kdata->pinst) - 1); + (void)strncpy(kdata->prealm, realm, sizeof(kdata->prealm) - 1); + return (kuserok(kdata, toname)); +} +#endif diff --git a/tee/Makefile b/tee/Makefile new file mode 100644 index 0000000..f4ca484 --- /dev/null +++ b/tee/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = tee + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = tee.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble tee.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/tee/Makefile.postamble b/tee/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/tee/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/tee/Makefile.preamble b/tee/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/tee/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/tee/PB.project b/tee/PB.project new file mode 100644 index 0000000..84dfa7d --- /dev/null +++ b/tee/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (tee.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, tee.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = tee; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/tee/tee.1 b/tee/tee.1 new file mode 100644 index 0000000..19d2d40 --- /dev/null +++ b/tee/tee.1 @@ -0,0 +1,90 @@ +.\" $NetBSD: tee.1,v 1.5 1997/10/20 00:37:11 lukem Exp $ +.\" +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)tee.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt TEE 1 +.Os +.Sh NAME +.Nm tee +.Nd pipe fitting +.Sh SYNOPSIS +.Nm +.Op Fl ai +.Op Ar file ... +.Sh DESCRIPTION +The +.Nm +utility copies standard input to standard output, +making a copy in zero or more files. +The output is unbuffered. +.Pp +The following options are available: +.Bl -tag -width Ds +.It Fl a +Append the output to the files rather than +overwriting them. +.It Fl i +Ignore the +.Dv SIGINT +signal. +.El +.Pp +The following operands are available: +.Bl -tag -width file +.It file +A pathname of an output +.Ar file . +.El +.Pp +The +.Nm +utility takes the default action for all signals, +except in the event of the +.Fl i +option. +.Pp +The +.Nm +utility exits 0 on success, and >0 if an error occurs. +.Sh STANDARDS +The +.Nm +function is expected to be +.Tn POSIX +.St -p1003.2 +compatible. diff --git a/tee/tee.c b/tee/tee.c new file mode 100644 index 0000000..e916d90 --- /dev/null +++ b/tee/tee.c @@ -0,0 +1,156 @@ +/* $NetBSD: tee.c,v 1.6 1997/10/20 00:37:11 lukem Exp $ */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tee.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: tee.c,v 1.6 1997/10/20 00:37:11 lukem Exp $"); +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct _list { + struct _list *next; + int fd; + char *name; +} LIST; +LIST *head; + +void add __P((int, char *)); +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + LIST *p; + int n, fd, rval, wval; + char *bp; + int append, ch, exitval; + char *buf; +#define BSIZE (8 * 1024) + + setlocale(LC_ALL, ""); + + append = 0; + while ((ch = getopt(argc, argv, "ai")) != -1) + switch((char)ch) { + case 'a': + append = 1; + break; + case 'i': + (void)signal(SIGINT, SIG_IGN); + break; + case '?': + default: + (void)fprintf(stderr, "usage: tee [-ai] [file ...]\n"); + exit(1); + } + argv += optind; + argc -= optind; + + if ((buf = malloc((size_t)BSIZE)) == NULL) + err(1, "malloc"); + + add(STDOUT_FILENO, "stdout"); + + for (exitval = 0; *argv; ++argv) + if ((fd = open(*argv, append ? O_WRONLY|O_CREAT|O_APPEND : + O_WRONLY|O_CREAT|O_TRUNC, DEFFILEMODE)) < 0) { + warn("%s", *argv); + exitval = 1; + } else + add(fd, *argv); + + while ((rval = read(STDIN_FILENO, buf, BSIZE)) > 0) + for (p = head; p; p = p->next) { + n = rval; + bp = buf; + do { + if ((wval = write(p->fd, bp, n)) == -1) { + warn("%s", p->name); + exitval = 1; + break; + } + bp += wval; + } while (n -= wval); + } + if (rval < 0) { + warn("read"); + exitval = 1; + } + + for (p = head; p; p = p->next) { + if (close(p->fd) == -1) { + warn("%s", p->name); + exitval = 1; + } + } + + exit(exitval); +} + +void +add(fd, name) + int fd; + char *name; +{ + LIST *p; + + if ((p = malloc((size_t)sizeof(LIST))) == NULL) + err(1, "malloc"); + p->fd = fd; + p->name = name; + p->next = head; + head = p; +} diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..eeca1a3 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,49 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = test + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = test.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble test.1\ + TEST.csh + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/test/Makefile.postamble b/test/Makefile.postamble new file mode 100644 index 0000000..75155d2 --- /dev/null +++ b/test/Makefile.postamble @@ -0,0 +1,6 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common + +OTHERSRCS += '[.1' + +after_install:: + $(LINKPRODUCT) $(DSTROOT)$(INSTALLDIR)/[ diff --git a/test/Makefile.preamble b/test/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/test/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/test/PB.project b/test/PB.project new file mode 100644 index 0000000..faa95c3 --- /dev/null +++ b/test/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (test.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, test.1, TEST.csh); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = test; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/test/TEST.csh b/test/TEST.csh new file mode 100644 index 0000000..672e1a0 --- /dev/null +++ b/test/TEST.csh @@ -0,0 +1,138 @@ +# $NetBSD: TEST.csh,v 1.2 1995/03/21 07:03:59 cgd Exp $ +# @(#)TEST.csh 5.2 (Berkeley) 4/30/93 + +#alias t '/usr/src/bin/test/obj/test \!*; echo $status' +alias t '/bin/test \!*; echo $status' + +echo 't -b /dev/ttyp2' +t -b /dev/ttyp2 +echo 't -b /dev/jb1a' +t -b /dev/jb1a + +echo 't -c test.c' +t -c test.c +echo 't -c /dev/tty' +t -c /dev/tty + +echo 't -d test.c' +t -d test.c +echo 't -d /etc' +t -d /etc + +echo 't -e noexist' +t -e noexist +echo 't -e test.c' +t -e test.c + +echo 't -f noexist' +t -f noexist +echo 't -f /dev/tty' +t -f /dev/tty +echo 't -f test.c' +t -f test.c + +echo 't -g test.c' +t -g test.c +echo 't -g /bin/ps' +t -g /bin/ps + +echo 't -n ""' +t -n "" +echo 't -n "hello"' +t -n "hello" + +echo 't -p test.c' +t -p test.c + +echo 't -r noexist' +t -r noexist +echo 't -r /etc/master.passwd' +t -r /etc/master.passwd +echo 't -r test.c' +t -r test.c + +echo 't -s noexist' +t -s noexist +echo 't -s /dev/null' +t -s /dev/null +echo 't -s test.c' +t -s test.c + +echo 't -t 20' +t -t 20 +echo 't -t 0' +t -t 0 + +echo 't -u test.c' +t -u test.c +echo 't -u /bin/rcp' +t -u /bin/rcp + +echo 't -w noexist' +t -w noexist +echo 't -w /etc/master.passwd' +t -w /etc/master.passwd +echo 't -w /dev/null' +t -w /dev/null + +echo 't -x noexist' +t -x noexist +echo 't -x /bin/ps' +t -x /bin/ps +echo 't -x /etc/motd' +t -x /etc/motd + +echo 't -z ""' +t -z "" +echo 't -z "foo"' +t -z "foo" + +echo 't "foo"' +t "foo" +echo 't ""' +t "" + +echo 't "hello" = "hello"' +t "hello" = "hello" +echo 't "hello" = "goodbye"' +t "hello" = "goodbye" + +echo 't "hello" != "hello"' +t "hello" != "hello" +echo 't "hello" != "goodbye"' +t "hello" != "goodbye" + +echo 't 200 -eq 200' +t 200 -eq 200 +echo 't 34 -eq 222' +t 34 -eq 222 + +echo 't 200 -ne 200' +t 200 -ne 200 +echo 't 34 -ne 222' +t 34 -ne 222 + +echo 't 200 -gt 200' +t 200 -gt 200 +echo 't 340 -gt 222' +t 340 -gt 222 + +echo 't 200 -ge 200' +t 200 -ge 200 +echo 't 34 -ge 222' +t 34 -ge 222 + +echo 't 200 -lt 200' +t 200 -lt 200 +echo 't 34 -lt 222' +t 34 -lt 222 + +echo 't 200 -le 200' +t 200 -le 200 +echo 't 340 -le 222' +t 340 -le 222 + +echo 't 700 -le 1000 -a -n "1" -a "20" = "20"' +t 700 -le 1000 -a -n "1" -a "20" = "20" +echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)' +t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \) diff --git a/test/[.1 b/test/[.1 new file mode 100644 index 0000000..9ed6386 --- /dev/null +++ b/test/[.1 @@ -0,0 +1 @@ +.so man1/test.1 \ No newline at end of file diff --git a/test/test.1 b/test/test.1 new file mode 100644 index 0000000..061189e --- /dev/null +++ b/test/test.1 @@ -0,0 +1,317 @@ +.\" $NetBSD: test.1,v 1.10 1997/11/12 00:48:21 mrg Exp $ +.\" +.\" Copyright (c) 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)test.1 8.1 (Berkeley) 5/31/93 +.\" +.Dd May 31, 1993 +.Dt TEST 1 +.Os +.Sh NAME +.Nm test , +.Nm [ +.Nd condition evaluation utility +.Sh SYNOPSIS +.Nm test +.Ar expression +.Nm [ +.Ar expression Cm ] +.Sh DESCRIPTION +The +.Nm test +utility evaluates the expression and, if it evaluates +to true, returns a zero (true) exit status; otherwise +it returns 1 (false). +If there is no expression, test also +returns 1 (false). +.Pp +All operators and flags are separate arguments to the +.Nm test +utility. +.Pp +The following primaries are used to construct expression: +.Bl -tag -width Ar +.It Fl b Ar file +True if +.Ar file +exists and is a block special +file. +.It Fl c Ar file +True if +.Ar file +exists and is a character +special file. +.It Fl d Ar file +True if +.Ar file +exists and is a directory. +.It Fl e Ar file +True if +.Ar file +exists (regardless of type). +.It Fl f Ar file +True if +.Ar file +exists and is a regular file. +.It Fl g Ar file +True if +.Ar file +exists and its set group ID flag +is set. +.It Fl h Ar file +True if +.Ar file +exists and is a symbolic link. +This operator is retained for compatibility with previous versions of +this program. Do not rely on its existence; use +.Fl L +instead. +.It Fl k Ar file +True if +.Ar file +exists and its sticky bit is set. +.It Fl n Ar string +True if the length of +.Ar string +is nonzero. +.It Fl p Ar file +True if +.Ar file +is a named pipe +.Po Tn FIFO Pc . +.It Fl r Ar file +True if +.Ar file +exists and is readable. +.It Fl s Ar file +True if +.Ar file +exists and has a size greater +than zero. +.It Fl t Ar file_descriptor +True if the file whose file descriptor number +is +.Ar file_descriptor +is open and is associated with a terminal. +.It Fl u Ar file +True if +.Ar file +exists and its set user ID flag +is set. +.It Fl w Ar file +True if +.Ar file +exists and is writable. +True +indicates only that the write flag is on. +The file is not writable on a read-only file +system even if this test indicates true. +.It Fl x Ar file +True if +.Ar file +exists and is executable. +True +indicates only that the execute flag is on. +If +.Ar file +is a directory, true indicates that +.Ar file +can be searched. +.It Fl z Ar string +True if the length of +.Ar string +is zero. +.It Fl L Ar file +True if +.Ar file +exists and is a symbolic link. +.It Fl O Ar file +True if +.Ar file +exists and its owner matches the effective user id of this process. +.It Fl G Ar file +True if +.Ar file +exists and its group matches the effective group id of this process. +.It Fl S Ar file +True if +.Ar file +exists and is a socket. +.It Ar file1 Fl nt Ar file2 +True if +.Ar file1 +exists and is newer than +.Ar file2 . +.It Ar file1 Fl ot Ar file2 +True if +.Ar file1 +exists and is older than +.Ar file2 . +.It Ar file1 Fl ef Ar file2 +True if +.Ar file1 +and +.Ar file2 +exist and refer to the same file. +.It Ar string +True if +.Ar string +is not the null +string. +.It Ar \&s\&1 Cm \&= Ar \&s\&2 +True if the strings +.Ar \&s\&1 +and +.Ar \&s\&2 +are identical. +.It Ar \&s\&1 Cm \&!= Ar \&s\&2 +True if the strings +.Ar \&s\&1 +and +.Ar \&s\&2 +are not identical. +.It Ar \&s\&1 Cm \&< Ar \&s\&2 +True if string +.Ar \&s\&1 +comes before +.Ar \&s\&2 +based on the ASCII value of their characters. +.It Ar \&s\&1 Cm \&> Ar \&s\&2 +True if string +.Ar \&s\&1 +comes after +.Ar \&s\&2 +based on the ASCII value of their characters. +.It Ar \&s\&1 +True if +.Ar \&s\&1 +is not the null +string. +.It Ar \&n\&1 Fl \&eq Ar \&n\&2 +True if the integers +.Ar \&n\&1 +and +.Ar \&n\&2 +are algebraically +equal. +.It Ar \&n\&1 Fl \&ne Ar \&n\&2 +True if the integers +.Ar \&n\&1 +and +.Ar \&n\&2 +are not +algebraically equal. +.It Ar \&n\&1 Fl \> Ar \&n\&2 +True if the integer +.Ar \&n\&1 +is algebraically +greater than the integer +.Ar \&n\&2 . +.It Ar \&n\&1 Fl \&ge Ar \&n\&2 +True if the integer +.Ar \&n\&1 +is algebraically +greater than or equal to the integer +.Ar \&n\&2 . +.It Ar \&n\&1 Fl \< Ar \&n\&2 +True if the integer +.Ar \&n\&1 +is algebraically less +than the integer +.Ar \&n\&2 . +.It Ar \&n\&1 Fl \&le Ar \&n\&2 +True if the integer +.Ar \&n\&1 +is algebraically less +than or equal to the integer +.Ar \&n\&2 . +.El +.Pp +These primaries can be combined with the following operators: +.Bl -tag -width Ar +.It Cm \&! Ar expression +True if +.Ar expression +is false. +.It Ar expression1 Fl a Ar expression2 +True if both +.Ar expression1 +and +.Ar expression2 +are true. +.It Ar expression1 Fl o Ar expression2 +True if either +.Ar expression1 +or +.Ar expression2 +are true. +.It Cm \&( Ns Ar expression Ns Cm \&) +True if expression is true. +.El +.Pp +The +.Fl a +operator has higher precedence than the +.Fl o +operator. +.Sh GRAMMAR AMBIGUITY +The +.Nm test +grammar is inherently ambiguous. In order to assure a degree of consistency, +the cases described in +.St -p1003.2 +section 4.62.4, +are evaluated consistently according to the rules specified in the +standards document. All other cases are subject to the ambiguity in the +command semantics. +.Sh RETURN VALUES +The +.Nm test +utility exits with one of the following values: +.Bl -tag -width Ds +.It 0 +expression evaluated to true. +.It 1 +expression evaluated to false or expression was +missing. +.It >1 +An error occurred. +.El +.Sh STANDARDS +The +.Nm test +utility implements a superset of the +.St -p1003.2 +specification. diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..366ccda --- /dev/null +++ b/test/test.c @@ -0,0 +1,468 @@ +/* $NetBSD: test.c,v 1.19 1998/07/28 11:41:59 mycroft Exp $ */ + +/* + * test(1); version 7-like -- author Erik Baalbergen + * modified by Eric Gisin to be used as built-in. + * modified by Arnold Robbins to add SVR3 compatibility + * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket). + * modified by J.T. Conklin for NetBSD. + * + * This program is in the Public Domain. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: test.c,v 1.19 1998/07/28 11:41:59 mycroft Exp $"); +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* test(1) accepts the following grammar: + oexpr ::= aexpr | aexpr "-o" oexpr ; + aexpr ::= nexpr | nexpr "-a" aexpr ; + nexpr ::= primary | "!" primary + primary ::= unary-operator operand + | operand binary-operator operand + | operand + | "(" oexpr ")" + ; + unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"| + "-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S"; + + binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"| + "-nt"|"-ot"|"-ef"; + operand ::= +*/ + +enum token { + EOI, + FILRD, + FILWR, + FILEX, + FILEXIST, + FILREG, + FILDIR, + FILCDEV, + FILBDEV, + FILFIFO, + FILSOCK, + FILSYM, + FILGZ, + FILTT, + FILSUID, + FILSGID, + FILSTCK, + FILNT, + FILOT, + FILEQ, + FILUID, + FILGID, + STREZ, + STRNZ, + STREQ, + STRNE, + STRLT, + STRGT, + INTEQ, + INTNE, + INTGE, + INTGT, + INTLE, + INTLT, + UNOT, + BAND, + BOR, + LPAREN, + RPAREN, + OPERAND +}; + +enum token_types { + UNOP, + BINOP, + BUNOP, + BBINOP, + PAREN +}; + +struct t_op { + const char *op_text; + short op_num, op_type; +} const ops [] = { + {"-r", FILRD, UNOP}, + {"-w", FILWR, UNOP}, + {"-x", FILEX, UNOP}, + {"-e", FILEXIST,UNOP}, + {"-f", FILREG, UNOP}, + {"-d", FILDIR, UNOP}, + {"-c", FILCDEV,UNOP}, + {"-b", FILBDEV,UNOP}, + {"-p", FILFIFO,UNOP}, + {"-u", FILSUID,UNOP}, + {"-g", FILSGID,UNOP}, + {"-k", FILSTCK,UNOP}, + {"-s", FILGZ, UNOP}, + {"-t", FILTT, UNOP}, + {"-z", STREZ, UNOP}, + {"-n", STRNZ, UNOP}, + {"-h", FILSYM, UNOP}, /* for backwards compat */ + {"-O", FILUID, UNOP}, + {"-G", FILGID, UNOP}, + {"-L", FILSYM, UNOP}, + {"-S", FILSOCK,UNOP}, + {"=", STREQ, BINOP}, + {"!=", STRNE, BINOP}, + {"<", STRLT, BINOP}, + {">", STRGT, BINOP}, + {"-eq", INTEQ, BINOP}, + {"-ne", INTNE, BINOP}, + {"-ge", INTGE, BINOP}, + {"-gt", INTGT, BINOP}, + {"-le", INTLE, BINOP}, + {"-lt", INTLT, BINOP}, + {"-nt", FILNT, BINOP}, + {"-ot", FILOT, BINOP}, + {"-ef", FILEQ, BINOP}, + {"!", UNOT, BUNOP}, + {"-a", BAND, BBINOP}, + {"-o", BOR, BBINOP}, + {"(", LPAREN, PAREN}, + {")", RPAREN, PAREN}, + {0, 0, 0} +}; + +char **t_wp; +struct t_op const *t_wp_op; + +static void syntax __P((const char *, const char *)); +static int oexpr __P((enum token)); +static int aexpr __P((enum token)); +static int nexpr __P((enum token)); +static int primary __P((enum token)); +static int binop __P((void)); +static int filstat __P((char *, enum token)); +static enum token t_lex __P((char *)); +static int getn __P((const char *)); +static int newerf __P((const char *, const char *)); +static int olderf __P((const char *, const char *)); +static int equalf __P((const char *, const char *)); + +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char **argv; +{ + int res; + + if (strcmp(argv[0], "[") == 0) { + if (strcmp(argv[--argc], "]")) + errx(2, "missing ]"); + argv[argc] = NULL; + } + + /* Implement special cases from POSIX.2, section 4.62.4 */ + switch (argc) { + case 1: + return 1; + case 2: + return (*argv[1] == '\0'); + case 3: + if (argv[1][0] == '!' && argv[1][1] == '\0') { + return !(*argv[2] == '\0'); + } + break; + case 4: + if (argv[1][0] != '!' || argv[1][1] != '\0') { + if (t_lex(argv[2]), + t_wp_op && t_wp_op->op_type == BINOP) { + t_wp = &argv[1]; + return (binop() == 0); + } + } + break; + case 5: + if (argv[1][0] == '!' && argv[1][1] == '\0') { + if (t_lex(argv[3]), + t_wp_op && t_wp_op->op_type == BINOP) { + t_wp = &argv[2]; + return !(binop() == 0); + } + } + break; + } + + t_wp = &argv[1]; + res = !oexpr(t_lex(*t_wp)); + + if (*t_wp != NULL && *++t_wp != NULL) + syntax(*t_wp, "unknown operand"); + + return res; +} + +static void +syntax(op, msg) + const char *op; + const char *msg; +{ + if (op && *op) + errx(2, "%s: %s", op, msg); + else + errx(2, "%s", msg); +} + +static int +oexpr(n) + enum token n; +{ + int res; + + res = aexpr(n); + if (t_lex(*++t_wp) == BOR) + return oexpr(t_lex(*++t_wp)) || res; + t_wp--; + return res; +} + +static int +aexpr(n) + enum token n; +{ + int res; + + res = nexpr(n); + if (t_lex(*++t_wp) == BAND) + return aexpr(t_lex(*++t_wp)) && res; + t_wp--; + return res; +} + +static int +nexpr(n) + enum token n; /* token */ +{ + if (n == UNOT) + return !nexpr(t_lex(*++t_wp)); + return primary(n); +} + +static int +primary(n) + enum token n; +{ + int res; + + if (n == EOI) + syntax(NULL, "argument expected"); + if (n == LPAREN) { + res = oexpr(t_lex(*++t_wp)); + if (t_lex(*++t_wp) != RPAREN) + syntax(NULL, "closing paren expected"); + return res; + } + if (t_wp_op && t_wp_op->op_type == UNOP) { + /* unary expression */ + if (*++t_wp == NULL) + syntax(t_wp_op->op_text, "argument expected"); + switch (n) { + case STREZ: + return strlen(*t_wp) == 0; + case STRNZ: + return strlen(*t_wp) != 0; + case FILTT: + return isatty(getn(*t_wp)); + default: + return filstat(*t_wp, n); + } + } + + if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) { + return binop(); + } + + return strlen(*t_wp) > 0; +} + +static int +binop() +{ + const char *opnd1, *opnd2; + struct t_op const *op; + + opnd1 = *t_wp; + (void) t_lex(*++t_wp); + op = t_wp_op; + + if ((opnd2 = *++t_wp) == (char *)0) + syntax(op->op_text, "argument expected"); + + switch (op->op_num) { + case STREQ: + return strcmp(opnd1, opnd2) == 0; + case STRNE: + return strcmp(opnd1, opnd2) != 0; + case STRLT: + return strcmp(opnd1, opnd2) < 0; + case STRGT: + return strcmp(opnd1, opnd2) > 0; + case INTEQ: + return getn(opnd1) == getn(opnd2); + case INTNE: + return getn(opnd1) != getn(opnd2); + case INTGE: + return getn(opnd1) >= getn(opnd2); + case INTGT: + return getn(opnd1) > getn(opnd2); + case INTLE: + return getn(opnd1) <= getn(opnd2); + case INTLT: + return getn(opnd1) < getn(opnd2); + case FILNT: + return newerf (opnd1, opnd2); + case FILOT: + return olderf (opnd1, opnd2); + case FILEQ: + return equalf (opnd1, opnd2); + default: + abort(); + /* NOTREACHED */ + } +} + +static int +filstat(nm, mode) + char *nm; + enum token mode; +{ + struct stat s; + + if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s)) + return 0; + + switch (mode) { + case FILRD: + return access(nm, R_OK) == 0; + case FILWR: + return access(nm, W_OK) == 0; + case FILEX: + return access(nm, X_OK) == 0; + case FILEXIST: + return access(nm, F_OK) == 0; + case FILREG: + return S_ISREG(s.st_mode); + case FILDIR: + return S_ISDIR(s.st_mode); + case FILCDEV: + return S_ISCHR(s.st_mode); + case FILBDEV: + return S_ISBLK(s.st_mode); + case FILFIFO: + return S_ISFIFO(s.st_mode); + case FILSOCK: + return S_ISSOCK(s.st_mode); + case FILSYM: + return S_ISLNK(s.st_mode); + case FILSUID: + return (s.st_mode & S_ISUID) != 0; + case FILSGID: + return (s.st_mode & S_ISGID) != 0; + case FILSTCK: + return (s.st_mode & S_ISVTX) != 0; + case FILGZ: + return s.st_size > (off_t)0; + case FILUID: + return s.st_uid == geteuid(); + case FILGID: + return s.st_gid == getegid(); + default: + return 1; + } +} + +static enum token +t_lex(s) + char *s; +{ + struct t_op const *op = ops; + + if (s == 0) { + t_wp_op = (struct t_op *)0; + return EOI; + } + while (op->op_text) { + if (strcmp(s, op->op_text) == 0) { + t_wp_op = op; + return op->op_num; + } + op++; + } + t_wp_op = (struct t_op *)0; + return OPERAND; +} + +/* atoi with error detection */ +static int +getn(s) + const char *s; +{ + char *p; + long r; + + errno = 0; + r = strtol(s, &p, 10); + + if (errno != 0) + errx(2, "%s: out of range", s); + + while (isspace(*p)) + p++; + + if (*p) + errx(2, "%s: bad number", s); + + return (int) r; +} + +static int +newerf (f1, f2) +const char *f1, *f2; +{ + struct stat b1, b2; + + return (stat (f1, &b1) == 0 && + stat (f2, &b2) == 0 && + b1.st_mtime > b2.st_mtime); +} + +static int +olderf (f1, f2) +const char *f1, *f2; +{ + struct stat b1, b2; + + return (stat (f1, &b1) == 0 && + stat (f2, &b2) == 0 && + b1.st_mtime < b2.st_mtime); +} + +static int +equalf (f1, f2) +const char *f1, *f2; +{ + struct stat b1, b2; + + return (stat (f1, &b1) == 0 && + stat (f2, &b2) == 0 && + b1.st_dev == b2.st_dev && + b1.st_ino == b2.st_ino); +} diff --git a/time/Makefile b/time/Makefile new file mode 100644 index 0000000..9cc989e --- /dev/null +++ b/time/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = time + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = time.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble time.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/time/Makefile.postamble b/time/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/time/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/time/Makefile.preamble b/time/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/time/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/time/PB.project b/time/PB.project new file mode 100644 index 0000000..3883220 --- /dev/null +++ b/time/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (time.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, time.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = time; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/time/time.1 b/time/time.1 new file mode 100644 index 0000000..4596a8f --- /dev/null +++ b/time/time.1 @@ -0,0 +1,123 @@ +.\" $NetBSD: time.1,v 1.7 1997/10/20 03:28:20 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)time.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt TIME 1 +.Os +.Sh NAME +.Nm time +.Nd time command execution +.Sh SYNOPSIS +.Nm +.Op Fl lp +.Ar utility +.Sh DESCRIPTION +The +.Nm +utility +executes and +times +.Ar utility . +After the +.Ar utility +finishes, +.Nm +writes the total time elapsed, +the time consumed by system overhead, +and the time used to execute +.Ar utility +to the standard error stream. +Times are reported in seconds. +.Pp +Available options: +.Bl -tag -width Ds +.It Fl l +The contents of the +.Em rusage +structure are printed. +.It Fl p +The output is formatted as specified by +.St -p1003.2-92 . +.El +.Pp +The +.Xr csh 1 +has its own and syntactically different builtin version of +.Nm "" . +The utility described here +is available as +.Pa /usr/bin/time +to +.Xr csh +users. +.Sh DIAGNOSTICS +The +.Nm +utility shall exit with one of the following values: +.Bl -tag -width indent +.It 1-125 +An error occurred in the +.Nm +utility. +.It 126 +The +.Ar utility +was found but could not be invoked. +.It 127 +The +.Ar utility +could not be found. +.El +.Pp +Otherwise, the exit status of +.Nm +shall be that of +.Ar utility . +.Sh SEE ALSO +.Xr csh 1 , +.Xr getrusage 2 +.Sh FILES +.Bl -tag -width /usr/include/sys/resource.h -compact +.It Pa /usr/include/sys/resource.h +.El +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . +.Sh BUGS +The granularity of seconds on microprocessors is crude and +can result in times being reported for CPU usage which are too large by +a second. diff --git a/time/time.c b/time/time.c new file mode 100644 index 0000000..cd8f573 --- /dev/null +++ b/time/time.c @@ -0,0 +1,173 @@ +/* $NetBSD: time.c,v 1.9 1997/10/20 03:28:21 lukem Exp $ */ + +/* + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1987, 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: time.c,v 1.9 1997/10/20 03:28:21 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int lflag; +int portableflag; + +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char **argv; +{ + int pid; + int ch, status; + struct timeval before, after; + struct rusage ru; + +#ifdef __GNUC__ /* XXX: borken gcc */ + (void)&argv; +#endif + lflag = 0; + while ((ch = getopt(argc, argv, "lp")) != -1) + switch((char)ch) { + case 'p': + portableflag = 1; + break; + case 'l': + lflag = 1; + break; + case '?': + default: + fprintf(stderr, "usage: time [-lp] command.\n"); + exit(1); + } + + if (!(argc -= optind)) + exit(0); + argv += optind; + + gettimeofday(&before, (struct timezone *)NULL); + switch(pid = vfork()) { + case -1: /* error */ + perror("time"); + exit(1); + /* NOTREACHED */ + case 0: /* child */ + execvp(*argv, argv); + perror(*argv); + _exit((errno == ENOENT) ? 127 : 126); + /* NOTREACHED */ + } + + /* parent */ + (void)signal(SIGINT, SIG_IGN); + (void)signal(SIGQUIT, SIG_IGN); + while (wait3(&status, 0, &ru) != pid); + gettimeofday(&after, (struct timezone *)NULL); + if (!WIFEXITED(status)) + fprintf(stderr, "Command terminated abnormally.\n"); + timersub(&after, &before, &after); + + if (portableflag) { + fprintf (stderr, "real %9ld.%02ld\n", + (long)after.tv_sec, (long)after.tv_usec/10000); + fprintf (stderr, "user %9ld.%02ld\n", + (long)ru.ru_utime.tv_sec, (long)ru.ru_utime.tv_usec/10000); + fprintf (stderr, "sys %9ld.%02ld\n", + (long)ru.ru_stime.tv_sec, (long)ru.ru_stime.tv_usec/10000); + } else { + + fprintf(stderr, "%9ld.%02ld real ", + (long)after.tv_sec, (long)after.tv_usec/10000); + fprintf(stderr, "%9ld.%02ld user ", + (long)ru.ru_utime.tv_sec, (long)ru.ru_utime.tv_usec/10000); + fprintf(stderr, "%9ld.%02ld sys\n", + (long)ru.ru_stime.tv_sec, (long)ru.ru_stime.tv_usec/10000); + } + + if (lflag) { + int hz = 100; /* XXX */ + long ticks; + + ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) + + hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) / 1000000; + + fprintf(stderr, "%10ld %s\n", + ru.ru_maxrss, "maximum resident set size"); + fprintf(stderr, "%10ld %s\n", ticks ? ru.ru_ixrss / ticks : 0, + "average shared memory size"); + fprintf(stderr, "%10ld %s\n", ticks ? ru.ru_idrss / ticks : 0, + "average unshared data size"); + fprintf(stderr, "%10ld %s\n", ticks ? ru.ru_isrss / ticks : 0, + "average unshared stack size"); + fprintf(stderr, "%10ld %s\n", + ru.ru_minflt, "page reclaims"); + fprintf(stderr, "%10ld %s\n", + ru.ru_majflt, "page faults"); + fprintf(stderr, "%10ld %s\n", + ru.ru_nswap, "swaps"); + fprintf(stderr, "%10ld %s\n", + ru.ru_inblock, "block input operations"); + fprintf(stderr, "%10ld %s\n", + ru.ru_oublock, "block output operations"); + fprintf(stderr, "%10ld %s\n", + ru.ru_msgsnd, "messages sent"); + fprintf(stderr, "%10ld %s\n", + ru.ru_msgrcv, "messages received"); + fprintf(stderr, "%10ld %s\n", + ru.ru_nsignals, "signals received"); + fprintf(stderr, "%10ld %s\n", + ru.ru_nvcsw, "voluntary context switches"); + fprintf(stderr, "%10ld %s\n", + ru.ru_nivcsw, "involuntary context switches"); + } + + exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE); +} diff --git a/true/Makefile b/true/Makefile new file mode 100644 index 0000000..ef1fc0a --- /dev/null +++ b/true/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = true + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = true.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble true.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/true/Makefile.postamble b/true/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/true/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/true/Makefile.preamble b/true/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/true/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/true/PB.project b/true/PB.project new file mode 100644 index 0000000..b26817e --- /dev/null +++ b/true/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (true.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, true.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = true; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/true/true.1 b/true/true.1 new file mode 100644 index 0000000..b022042 --- /dev/null +++ b/true/true.1 @@ -0,0 +1,60 @@ +.\" $NetBSD: true.1,v 1.5 1997/10/20 01:00:41 lukem Exp $ +.\" +.\" Copyright (c) 1983, 1985, 1990 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)true.1 6.4 (Berkeley) 6/27/91 +.\" $NetBSD: true.1,v 1.5 1997/10/20 01:00:41 lukem Exp $ +.\" +.Dd June 27, 1991 +.Dt TRUE 1 +.Os +.Sh NAME +.Nm true +.Nd Return true value. +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +utility always returns with exit code zero. +.Sh SEE ALSO +.Xr csh 1 , +.Xr sh 1 , +.Xr false 1 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . diff --git a/true/true.c b/true/true.c new file mode 100644 index 0000000..f7af7e9 --- /dev/null +++ b/true/true.c @@ -0,0 +1 @@ +int main () { exit(0); } diff --git a/uname/Makefile b/uname/Makefile new file mode 100644 index 0000000..1e14989 --- /dev/null +++ b/uname/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = uname + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = uname.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble uname.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/uname/Makefile.postamble b/uname/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/uname/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/uname/Makefile.preamble b/uname/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/uname/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/uname/PB.project b/uname/PB.project new file mode 100644 index 0000000..e715a43 --- /dev/null +++ b/uname/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (uname.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, uname.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = uname; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/uname/uname.1 b/uname/uname.1 new file mode 100644 index 0000000..685a07f --- /dev/null +++ b/uname/uname.1 @@ -0,0 +1,88 @@ +.\" $NetBSD: uname.1,v 1.7 1997/10/20 02:16:38 lukem Exp $ +.\" +.\" Copyright (c) 1990 The Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)du.1 6.13 (Berkeley) 6/20/91 +.\" $NetBSD: uname.1,v 1.7 1997/10/20 02:16:38 lukem Exp $ +.\" +.Dd January 26, 1994 +.Dt UNAME 1 +.Os +.Sh NAME +.Nm uname +.Nd Print operating system name +.Sh SYNOPSIS +.Nm +.Op Fl amnpsrv +.Sh DESCRIPTION +The +.Nm +utility writes symbols representing one or more system characteristics +to the standard output. +.Pp +The following options are available: +.Bl -tag -width indent +.It Fl a +Behave as though all of the options +.Fl mnrsv +were specified. +.It Fl m +print the machine hardware name. +.It Fl n +print the nodename (the nodename may be a name +that the system is known by to a communications +network). +.It Fl p +print the generic processor type. +.It Fl s +print the operating system name. +.It Fl r +print the operating system release. +.It Fl v +print the operating system version. +.El +.Pp +If no options are specified, +.Nm +prints the operating system name as if the +.Fl s +option had been specified. +.Sh SEE ALSO +.Xr hostname 1 , +.Xr machine 1 , +.Xr uname 3 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . + diff --git a/uname/uname.c b/uname/uname.c new file mode 100644 index 0000000..72a6178 --- /dev/null +++ b/uname/uname.c @@ -0,0 +1,168 @@ +/* $NetBSD: uname.c,v 1.9 1997/10/20 02:16:39 lukem Exp $ */ + +/* + * Copyright (c) 1994 Winning Strategies, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Winning Strategies, Inc. + * 4. The name of Winning Strategies, Inc. may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: uname.c,v 1.9 1997/10/20 02:16:39 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include + +int main __P((int, char **)); +static void usage __P((void)); + +#define PRINT_SYSNAME 0x01 +#define PRINT_NODENAME 0x02 +#define PRINT_RELEASE 0x04 +#define PRINT_VERSION 0x08 +#define PRINT_MACHINE 0x10 +#define PRINT_PROCESSOR 0x20 +#define PRINT_ALL 0x3f + +int +main(argc, argv) + int argc; + char **argv; +{ + struct utsname u; + int c; + int space = 0; + int print_mask = 0; + + setlocale(LC_ALL, ""); + + while ((c = getopt(argc,argv,"amnprsv")) != -1 ) { + switch ( c ) { + case 'a': + print_mask |= PRINT_ALL; + break; + case 'm': + print_mask |= PRINT_MACHINE; + break; + case 'n': + print_mask |= PRINT_NODENAME; + break; + case 'p': + print_mask |= PRINT_PROCESSOR; + break; + case 'r': + print_mask |= PRINT_RELEASE; + break; + case 's': + print_mask |= PRINT_SYSNAME; + break; + case 'v': + print_mask |= PRINT_VERSION; + break; + default: + usage(); + /* NOTREACHED */ + } + } + + if (optind != argc) { + usage(); + /* NOTREACHED */ + } + + if (!print_mask) { + print_mask = PRINT_SYSNAME; + } + + if (uname(&u)) { + err(1, "uname"); + /* NOTREACHED */ + } + + /* + * Let's allow the user to override the output of uname via the shell environment. + * This is a useful feature for cross-compiling (eg. during an OS bringup). + * Otherwise, you have to hack your kernel with the desired strings. + */ + { + char *s; + s = getenv ("UNAME_SYSNAME"); if (s) strncpy (u.sysname, s, sizeof (u.sysname)); + s = getenv ("UNAME_NODENAME"); if (s) strncpy (u.nodename, s, sizeof (u.nodename)); + s = getenv ("UNAME_RELEASE"); if (s) strncpy (u.release, s, sizeof (u.release)); + s = getenv ("UNAME_VERSION"); if (s) strncpy (u.version, s, sizeof (u.version)); + s = getenv ("UNAME_MACHINE"); if (s) strncpy (u.machine, s, sizeof (u.machine)); + } + + if (print_mask & PRINT_SYSNAME) { + space++; + fputs(u.sysname, stdout); + } + if (print_mask & PRINT_NODENAME) { + if (space++) putchar(' '); + fputs(u.nodename, stdout); + } + if (print_mask & PRINT_RELEASE) { + if (space++) putchar(' '); + fputs(u.release, stdout); + } + if (print_mask & PRINT_VERSION) { + if (space++) putchar(' '); + fputs(u.version, stdout); + } + if (print_mask & PRINT_MACHINE) { + if (space++) putchar(' '); + fputs(u.machine, stdout); + } + if (print_mask & PRINT_PROCESSOR) { + if (space++) putchar(' '); +#if defined(__ppc__) + fputs("powerpc", stdout); +#elif defined(__i386__) + fputs("i386", stdout); +#else + fputs("unknown", stdout); +#endif + } + putchar('\n'); + + exit(0); + /* NOTREACHED */ +} + +static void +usage() +{ + fprintf(stderr, "usage: uname [-amnprsv]\n"); + exit(1); +} diff --git a/users/Makefile b/users/Makefile new file mode 100644 index 0000000..e7b7ddd --- /dev/null +++ b/users/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = users + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = users.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble users.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/users/Makefile.postamble b/users/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/users/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/users/Makefile.preamble b/users/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/users/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/users/PB.project b/users/PB.project new file mode 100644 index 0000000..f895ea9 --- /dev/null +++ b/users/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (users.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, users.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = users; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/users/users.1 b/users/users.1 new file mode 100644 index 0000000..6629f57 --- /dev/null +++ b/users/users.1 @@ -0,0 +1,61 @@ +.\" $NetBSD: users.1,v 1.5 1997/10/20 02:41:21 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)users.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt USERS 1 +.Os BSD 3 +.Sh NAME +.Nm users +.Nd list current users +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +lists the login names of the users currently on the system, +in sorted order, space separated, on a single line. +.Sh FILES +.Bl -tag -width /var/run/utmp +.It Pa /var/run/utmp +.El +.Sh SEE ALSO +.Xr finger 1 , +.Xr last 1 , +.Xr who 1 , +.Xr utmp 5 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . diff --git a/users/users.c b/users/users.c new file mode 100644 index 0000000..5e243cd --- /dev/null +++ b/users/users.c @@ -0,0 +1,125 @@ +/* $NetBSD: users.c,v 1.7 1998/02/03 04:19:15 perry Exp $ */ + +/* + * Copyright (c) 1980, 1987, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1980, 1987, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)users.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: users.c,v 1.7 1998/02/03 04:19:15 perry Exp $"); +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +typedef char namebuf[UT_NAMESIZE]; + +int main __P((int, char **)); +int scmp __P((const void *, const void *)); + +int +main(argc, argv) + int argc; + char **argv; +{ + namebuf *names = NULL; + int ncnt = 0; + int nmax = 0; + int cnt; + struct utmp utmp; + int ch; + + while ((ch = getopt(argc, argv, "")) != -1) + switch(ch) { + case '?': + default: + (void)fprintf(stderr, "usage: users\n"); + exit(1); + } + argc -= optind; + argv += optind; + + if (!freopen(_PATH_UTMP, "r", stdin)) { + err(1, "can't open %s", _PATH_UTMP); + /* NOTREACHED */ + } + + while (fread((char *)&utmp, sizeof(utmp), 1, stdin) == 1) { + if (*utmp.ut_name) { + if (ncnt >= nmax) { + nmax += 32; + names = realloc(names, + sizeof (*names) * nmax); + + if (!names) { + err(1, "realloc"); + /* NOTREACHED */ + } + } + + (void)strncpy(names[ncnt], utmp.ut_name, UT_NAMESIZE); + ++ncnt; + } + } + + if (ncnt) { + qsort(names, ncnt, UT_NAMESIZE, scmp); + (void)printf("%.*s", UT_NAMESIZE, names[0]); + for (cnt = 1; cnt < ncnt; ++cnt) + if (strncmp(names[cnt], names[cnt - 1], UT_NAMESIZE)) + (void)printf(" %.*s", UT_NAMESIZE, names[cnt]); + (void)printf("\n"); + } + exit(0); +} + +int +scmp(p, q) + const void *p, *q; +{ + return(strncmp((char *) p, (char *) q, UT_NAMESIZE)); +} diff --git a/w/Makefile b/w/Makefile new file mode 100644 index 0000000..3c5c7cf --- /dev/null +++ b/w/Makefile @@ -0,0 +1,51 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = w + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = extern.h + +CFILES = fmt.c proc_compare.c pr_time.c w.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble uptime.1 w.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +NEXTSTEP_PB_CFLAGS = -traditional-cpp -Wno-error + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/w/Makefile.postamble b/w/Makefile.postamble new file mode 100644 index 0000000..d6c7e60 --- /dev/null +++ b/w/Makefile.postamble @@ -0,0 +1,7 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common + +INSTALL_AS_GROUP = kmem +INSTALL_PERMISSIONS = 2555 + +after_install:: + $(LINKPRODUCT) $(DSTROOT)$(INSTALLDIR)/uptime diff --git a/w/Makefile.preamble b/w/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/w/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/w/PB.project b/w/PB.project new file mode 100644 index 0000000..f2e8fd2 --- /dev/null +++ b/w/PB.project @@ -0,0 +1,28 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (extern.h); + OTHER_LINKED = (fmt.c, proc_compare.c, pr_time.c, w.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, uptime.1, w.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_COMPILEROPTIONS = "-traditional-cpp -Wno-error"; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = w; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/w/extern.h b/w/extern.h new file mode 100644 index 0000000..7562e03 --- /dev/null +++ b/w/extern.h @@ -0,0 +1,43 @@ +/* $NetBSD: extern.h,v 1.3 1996/06/07 01:39:16 thorpej Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)extern.h 8.1 (Berkeley) 6/6/93 + */ + +struct proc; +void fmt_puts __P((char *, int *)); +void fmt_putc __P((int, int *)); +void pr_attime __P((time_t *, time_t *)); +void pr_idle __P((time_t)); +int proc_compare __P((struct proc *, struct proc *)); diff --git a/w/fmt.c b/w/fmt.c new file mode 100644 index 0000000..c3606ab --- /dev/null +++ b/w/fmt.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include +/*#include "ps.h"*/ +#include "extern.h" + +void +fmt_puts(s, leftp) + char *s; + int *leftp; +{ + static char *v = 0, *nv; + static int maxlen = 0; + int len; + + if (*leftp == 0) + return; + len = strlen(s) * 4 + 1; + if (len > maxlen) { + if (maxlen == 0) + maxlen = getpagesize(); + while (len > maxlen) + maxlen *= 2; + nv = realloc(v, maxlen); + if (nv == 0) + return; + v = nv; + } + strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE); + if (*leftp != -1) { + len = strlen(v); + if (len > *leftp) { + v[*leftp] = '\0'; + *leftp = 0; + } else + *leftp -= len; + } + printf("%s", v); +} + +void +fmt_putc(c, leftp) + int c; + int *leftp; +{ + + if (*leftp == 0) + return; + if (*leftp != -1) + *leftp -= 1; + putchar(c); +} diff --git a/w/pr_time.c b/w/pr_time.c new file mode 100644 index 0000000..e05edb5 --- /dev/null +++ b/w/pr_time.c @@ -0,0 +1,116 @@ +/* $NetBSD: pr_time.c,v 1.9 1998/04/02 11:34:23 kleink Exp $ */ + +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94"; +#else +__RCSID("$NetBSD: pr_time.c,v 1.9 1998/04/02 11:34:23 kleink Exp $"); +#endif +#endif /* not lint */ + +#include +#include + +#include +#include +#include +#include + +#include "extern.h" + +/* + * pr_attime -- + * Print the time since the user logged in. + * + * Note: SCCS forces the bizarre string manipulation, things like + * %I% get replaced in the source code. + */ +void +pr_attime(started, now) + time_t *started, *now; +{ + static char buf[256]; + int tnow_yday; + struct tm *tp; + time_t diff; + char *fmt; + + tnow_yday = localtime(now)->tm_yday; + tp = localtime(started); + diff = *now - *started; + + /* If more than a week, use day-month-year. */ + if (diff > SECSPERDAY * DAYSPERWEEK) + fmt = "%d%b%y"; + + /* If not today, use day-hour-am/pm. */ + else if (tp->tm_yday != tnow_yday) + fmt = __CONCAT("%a%", "I%p"); + + /* Default is hh:mm{am,pm}. */ + else + fmt = __CONCAT("%l:%", "M%p"); + + (void)strftime(buf, sizeof(buf), fmt, tp); + buf[sizeof(buf) - 1] = '\0'; + (void)fputs(buf, stdout); +} + +/* + * pr_idle -- + * Display the idle time. + */ +void +pr_idle(idle) + time_t idle; +{ + int days = idle / SECSPERDAY; + + /* If idle more than 36 hours, print as a number of days. */ + if (idle >= 36 * SECSPERHOUR) + printf(days == 1 ? " %dday " : " %ddays ", days); + + /* If idle more than an hour, print as HH:MM. */ + else if (idle >= SECSPERHOUR) + (void)printf(" %2d:%02d ", + (int)(idle / SECSPERHOUR), + (int)((idle % SECSPERHOUR) / SECSPERMIN)); + + /* Else print the minutes idle. */ + else + (void)printf(" %2d ", (int)(idle / SECSPERMIN)); +} diff --git a/w/proc_compare.c b/w/proc_compare.c new file mode 100644 index 0000000..7a15cac --- /dev/null +++ b/w/proc_compare.c @@ -0,0 +1,127 @@ +/* $NetBSD: proc_compare.c,v 1.7 1997/10/20 02:49:14 mrg Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)proc_compare.c 8.2 (Berkeley) 9/23/93"; +#else +__RCSID("$NetBSD: proc_compare.c,v 1.7 1997/10/20 02:49:14 mrg Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include + +#include "extern.h" + +/* + * Returns 1 if p2 is "better" than p1 + * + * The algorithm for picking the "interesting" process is thus: + * + * 1) Only foreground processes are eligible - implied. + * 2) Runnable processes are favored over anything else. The runner + * with the highest cpu utilization is picked (p_estcpu). Ties are + * broken by picking the highest pid. + * 3) The sleeper with the shortest sleep time is next. With ties, + * we pick out just "short-term" sleepers (P_SINTR == 0). + * 4) Further ties are broken by picking the highest pid. + * + * If you change this, be sure to consider making the change in the kernel + * too (^T in kern/tty.c). + * + * TODO - consider whether pctcpu should be used. + */ + +#define ISRUN(p) (((p)->p_stat == SRUN) || ((p)->p_stat == SIDL)) +#define TESTAB(a, b) ((a)<<1 | (b)) +#define ONLYA 2 +#define ONLYB 1 +#define BOTH 3 + +int +proc_compare(p1, p2) + struct proc *p1, *p2; +{ + + if (p1 == NULL) + return (1); + /* + * see if at least one of them is runnable + */ + switch (TESTAB(ISRUN(p1), ISRUN(p2))) { + case ONLYA: + return (0); + case ONLYB: + return (1); + case BOTH: + /* + * tie - favor one with highest recent cpu utilization + */ + if (p2->p_estcpu > p1->p_estcpu) + return (1); + if (p1->p_estcpu > p2->p_estcpu) + return (0); + return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ + } + /* + * weed out zombies + */ + switch (TESTAB(p1->p_stat == SZOMB, p2->p_stat == SZOMB)) { + case ONLYA: + return (1); + case ONLYB: + return (0); + case BOTH: + return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ + } + /* + * pick the one with the smallest sleep time + */ + if (p2->p_slptime > p1->p_slptime) + return (0); + if (p1->p_slptime > p2->p_slptime) + return (1); + /* + * favor one sleeping in a non-interruptible sleep + */ + if (p1->p_flag & P_SINTR && (p2->p_flag & P_SINTR) == 0) + return (1); + if (p2->p_flag & P_SINTR && (p1->p_flag & P_SINTR) == 0) + return (0); + return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ +} diff --git a/w/uptime.1 b/w/uptime.1 new file mode 100644 index 0000000..85ca182 --- /dev/null +++ b/w/uptime.1 @@ -0,0 +1,62 @@ +.\" $NetBSD: uptime.1,v 1.7 1997/10/20 02:49:15 mrg Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)uptime.1 8.2 (Berkeley) 4/18/94 +.\" +.Dd April 18, 1994 +.Dt UPTIME 1 +.Os BSD 3 +.Sh NAME +.Nm uptime +.Nd show how long system has been running +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +utility displays the current time, +the length of time the system has been up, +the number of users, and the load average of the system over the last +1, 5, and 15 minutes. +.Sh FILES +.Bl -tag -width /netbsd +.It Pa /netbsd +system name list +.El +.Sh SEE ALSO +.Xr w 1 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . diff --git a/w/w.1 b/w/w.1 new file mode 100644 index 0000000..3517a2e --- /dev/null +++ b/w/w.1 @@ -0,0 +1,143 @@ +.\" $NetBSD: w.1,v 1.8 1997/11/01 03:28:22 mycroft Exp $ +.\" +.\" Copyright (c) 1980, 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)w.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt W 1 +.Os BSD 4 +.Sh NAME +.Nm w +.Nd "who present users are and what they are doing" +.Sh SYNOPSIS +.Nm +.Op Fl hin +.Op Fl M Ar core +.Op Fl N Ar system +.Op Ar user +.Sh DESCRIPTION +The +.Nm +utility prints a summary of the current activity on the system, +including what each user is doing. +The first line displays the current time of day, how long the system has +been running, the number of users logged into the system, and the load +averages. +The load average numbers give the number of jobs in the run queue averaged +over 1, 5 and 15 minutes. +.Pp +The fields output are the user's login name, the name of the terminal the +user is on, the host from which the user is logged in, the time the user +logged on, the time since the user last typed anything, +and the name and arguments of the current process. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl h +Suppress the heading. +.It Fl i +Output is sorted by idle time. +.It Fl M +Extract values associated with the name list from the specified +core instead of the default +.Dq /dev/kmem . +.It Fl N +Extract the name list from the specified system instead of the +default +.Dq /netbsd . +.It Fl n +Show network addresses as numbers (normally +.Nm +interprets addresses and attempts to display them symbolically). +.El +.Pp +If a +.Ar user +name is specified, the output is restricted to that user. +.Sh FILES +.Bl -tag -width /var/run/utmp -compact +.It Pa /var/run/utmp +list of users on the system +.El +.Sh SEE ALSO +.Xr who 1 , +.Xr finger 1 , +.Xr ps 1 , +.Xr uptime 1 +.Sh BUGS +The notion of the +.Dq current process +is muddy. +The current algorithm is ``the highest numbered process on the terminal +that is not ignoring interrupts, or, if there is none, the highest numbered +process on the terminal''. +This fails, for example, in critical sections of programs like the shell +and editor, or when faulty programs running in the background fork and fail +to ignore interrupts. +(In cases where no process can be found, +.Nm +prints +.Dq \- . ) +.Pp +The +.Tn CPU +time is only an estimate, in particular, if someone leaves a background +process running after logging out, the person currently on that terminal is +.Dq charged +with the time. +.Pp +Background processes are not shown, even though they account for +much of the load on the system. +.Pp +Sometimes processes, typically those in the background, are printed with +null or garbaged arguments. +In these cases, the name of the command is printed in parentheses. +.Pp +The +.Nm +utility does not know about the new conventions for detection of background +jobs. +It will sometimes find a background job instead of the right one. +.Sh COMPATIBILITY +The +.Fl f , +.Fl l , +.Fl s , +and +.Fl w +flags are no longer supported. +.Sh HISTORY +The +.Nm +command appeared in +.Ux 3.0 . diff --git a/w/w.c b/w/w.c new file mode 100644 index 0000000..7e52c79 --- /dev/null +++ b/w/w.c @@ -0,0 +1,476 @@ +/* $NetBSD: w.c,v 1.30 1998/07/06 07:50:20 mrg Exp $ */ + +/*- + * Copyright (c) 1980, 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)w.c 8.6 (Berkeley) 6/30/94"; +#else +__RCSID("$NetBSD: w.c,v 1.30 1998/07/06 07:50:20 mrg Exp $"); +#endif +#endif /* not lint */ + +/* + * w - print system status (who and what) + * + * This program is similar to the systat command on Tenex/Tops 10/20 + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "extern.h" + +struct timeval boottime; +struct utmp utmp; +struct winsize ws; +kvm_t *kd; +time_t now; /* the current time of day */ +time_t uptime; /* time of last reboot & elapsed time since */ +int ttywidth; /* width of tty */ +int argwidth; /* width of tty */ +int header = 1; /* true if -h flag: don't print heading */ +int nflag; /* true if -n flag: don't convert addrs */ +int sortidle; /* sort bu idle time */ +char *sel_user; /* login of particular user selected */ +char domain[MAXHOSTNAMELEN + 1]; + +/* + * One of these per active utmp entry. + */ +struct entry { + struct entry *next; + struct utmp utmp; + dev_t tdev; /* dev_t of terminal */ + time_t idle; /* idle time of terminal in seconds */ + struct kinfo_proc *kp; /* `most interesting' proc */ +} *ep, *ehead = NULL, **nextp = &ehead; + +static void pr_args __P((struct kinfo_proc *)); +static void pr_header __P((time_t *, int)); +static struct stat + *ttystat __P((char *)); +static void usage __P((int)); +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char **argv; +{ + extern char *__progname; + struct kinfo_proc *kp; + struct hostent *hp; + struct stat *stp; + FILE *ut; + struct in_addr l; + int ch, i, nentries, nusers, wcmd; + gid_t egid = getegid(); + char *memf, *nlistf, *p, *x; + char buf[MAXHOSTNAMELEN], errbuf[_POSIX2_LINE_MAX]; + + (void)setegid(getgid()); + + /* Are we w(1) or uptime(1)? */ + p = __progname; + if (*p == '-') + p++; + if (*p == 'u') { + wcmd = 0; + p = ""; + } else { + wcmd = 1; + p = "hiflM:N:nsuw"; + } + + memf = nlistf = NULL; + while ((ch = getopt(argc, argv, p)) != -1) + switch (ch) { + case 'h': + header = 0; + break; + case 'i': + sortidle = 1; + break; + case 'M': + header = 0; + memf = optarg; + break; + case 'N': + nlistf = optarg; + break; + case 'n': + nflag = 1; + break; + case 'f': case 'l': case 's': case 'u': case 'w': + warnx("[-flsuw] no longer supported"); + /* FALLTHROUGH */ + case '?': + default: + usage(wcmd); + } + argc -= optind; + argv += optind; + + /* + * Discard setgid privileges. If not the running kernel, we toss + * them away totally so that bad guys can't print interesting stuff + * from kernel memory, otherwise switch back to kmem for the + * duration of the kvm_openfiles() call. + */ + if (nlistf != NULL || memf != NULL) + (void)setgid(getgid()); + else + (void)setegid(egid); + + if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) + errx(1, "%s", errbuf); + + /* get rid of it now anyway */ + if (nlistf == NULL && memf == NULL) + (void)setgid(getgid()); + + (void)time(&now); + if ((ut = fopen(_PATH_UTMP, "r")) == NULL) + err(1, "%s", _PATH_UTMP); + + if (*argv) + sel_user = *argv; + + for (nusers = 0; fread(&utmp, sizeof(utmp), 1, ut);) { + if (utmp.ut_name[0] == '\0') + continue; + ++nusers; + if (wcmd == 0 || (sel_user && + strncmp(utmp.ut_name, sel_user, UT_NAMESIZE) != 0)) + continue; + if ((ep = calloc(1, sizeof(struct entry))) == NULL) + err(1, "%s", ""); + *nextp = ep; + nextp = &(ep->next); + memmove(&(ep->utmp), &utmp, sizeof(struct utmp)); + if (!(stp = ttystat(ep->utmp.ut_line))) + continue; + ep->tdev = stp->st_rdev; +#ifdef CPU_CONSDEV + /* + * If this is the console device, attempt to ascertain + * the true console device dev_t. + */ + if (ep->tdev == 0) { + int mib[2]; + size_t size; + + mib[0] = CTL_MACHDEP; + mib[1] = CPU_CONSDEV; + size = sizeof(dev_t); + (void) sysctl(mib, 2, &ep->tdev, &size, NULL, 0); + } +#endif + if ((ep->idle = now - stp->st_atime) < 0) + ep->idle = 0; + } + (void)fclose(ut); + + if (header || wcmd == 0) { + pr_header(&now, nusers); + if (wcmd == 0) + exit (0); + } + +#define HEADER "USER TTY FROM LOGIN@ IDLE WHAT\n" +#define WUSED (sizeof (HEADER) - sizeof ("WHAT\n")) + (void)printf(HEADER); + + if ((kp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nentries)) == NULL) + errx(1, "%s", kvm_geterr(kd)); + for (i = 0; i < nentries; i++, kp++) { +#ifdef __APPLE__ + struct proc *p = (struct proc *)&kp->kp_proc; +#else + struct proc *p = &kp->kp_proc; +#endif + struct eproc *e; + + if (p->p_stat == SIDL || p->p_stat == SZOMB) + continue; + e = &kp->kp_eproc; + for (ep = ehead; ep != NULL; ep = ep->next) { + if (ep->tdev == e->e_tdev && e->e_pgid == e->e_tpgid) { + /* + * Proc is in foreground of this terminal + */ +#ifdef __APPLE__ + if (proc_compare((struct proc *)&ep->kp->kp_proc, p)) +#else + if (proc_compare(&ep->kp->kp_proc, p)) +#endif + ep->kp = kp; + break; + } + } + } + if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 && + ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 && + ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) || ws.ws_col == 0) + ttywidth = 79; + else + ttywidth = ws.ws_col - 1; + argwidth = ttywidth - WUSED; + if (argwidth < 4) + argwidth = 8; + /* sort by idle time */ + if (sortidle && ehead != NULL) { + struct entry *from = ehead, *save; + + ehead = NULL; + while (from != NULL) { + for (nextp = &ehead; + (*nextp) && from->idle >= (*nextp)->idle; + nextp = &(*nextp)->next) + continue; + save = from; + from = from->next; + save->next = *nextp; + *nextp = save; + } + } + + if (!nflag) { + int rv; + + rv = gethostname(domain, sizeof(domain)); + domain[sizeof(domain) - 1] = '\0'; + if (rv < 0 || (p = strchr(domain, '.')) == 0) + domain[0] = '\0'; + else + memmove(domain, p, strlen(p) + 1); + } + + for (ep = ehead; ep != NULL; ep = ep->next) { + p = *ep->utmp.ut_host ? ep->utmp.ut_host : "-"; + for (x = p; x < p + UT_HOSTSIZE; x++) + if (*x == '\0' || *x == ':') + break; + if (x == p + UT_HOSTSIZE || *x != ':') + x = NULL; + else + *x++ = '\0'; + + if (!nflag && inet_aton(p, &l) && + (hp = gethostbyaddr((char *)&l, sizeof(l), AF_INET))) { + if (domain[0] != '\0') { + p = hp->h_name; + p += strlen(hp->h_name); + p -= strlen(domain); + if (p > hp->h_name && strcmp(p, domain) == 0) + *p = '\0'; + } + p = hp->h_name; + } + if (x) { + (void)snprintf(buf, sizeof(buf), "%s:%.*s", p, + (int)(ep->utmp.ut_host + UT_HOSTSIZE - x), x); + p = buf; + } + (void)printf("%-*.*s %-2.2s %-*.*s ", + UT_NAMESIZE, UT_NAMESIZE, ep->utmp.ut_name, + strncmp(ep->utmp.ut_line, "tty", 3) ? + ep->utmp.ut_line : ep->utmp.ut_line + 3, + UT_HOSTSIZE, UT_HOSTSIZE, *p ? p : "-"); + pr_attime(&ep->utmp.ut_time, &now); + pr_idle(ep->idle); + pr_args(ep->kp); + printf("\n"); + } + exit(0); +} + +static void +pr_args(kp) + struct kinfo_proc *kp; +{ + char **argv; + int left; + + if (kp == 0) + goto nothing; + left = argwidth; + argv = kvm_getargv(kd, kp, argwidth); + if (argv == 0) + goto nothing; + while (*argv) { + fmt_puts(*argv, &left); + argv++; + fmt_putc(' ', &left); + } + return; +nothing: + putchar('-'); +} + +static void +pr_header(nowp, nusers) + time_t *nowp; + int nusers; +{ + double avenrun[3]; + time_t uptime; + int days, hrs, i, mins; + int mib[2]; + size_t size; + char buf[256]; + + /* + * Print time of day. + * + * SCCS forces the string manipulation below, as it replaces + * %, M, and % in a character string with the file name. + */ + (void)strftime(buf, sizeof(buf), + __CONCAT("%l:%","M%p"), localtime(nowp)); + buf[sizeof(buf) - 1] = '\0'; + (void)printf("%s ", buf); + + /* + * Print how long system has been up. + * (Found by looking getting "boottime" from the kernel) + */ + mib[0] = CTL_KERN; + mib[1] = KERN_BOOTTIME; + size = sizeof(boottime); + if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && + boottime.tv_sec != 0) { + uptime = now - boottime.tv_sec; + uptime += 30; + if (uptime > SECSPERMIN) { + days = uptime / SECSPERDAY; + uptime %= SECSPERDAY; + hrs = uptime / SECSPERHOUR; + uptime %= SECSPERHOUR; + mins = uptime / SECSPERMIN; + (void)printf(" up"); + if (days > 0) + (void)printf(" %d day%s,", days, + days > 1 ? "s" : ""); + if (hrs > 0 && mins > 0) + (void)printf(" %2d:%02d,", hrs, mins); + else { + if (hrs > 0) + (void)printf(" %d hr%s,", + hrs, hrs > 1 ? "s" : ""); + if (mins > 0) + (void)printf(" %d min%s,", + mins, mins > 1 ? "s" : ""); + } + } + } + + /* Print number of users logged in to system */ + (void)printf(" %d user%s", nusers, nusers != 1 ? "s" : ""); + + /* + * Print 1, 5, and 15 minute load averages. + */ + if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) == -1) + (void)printf(", no load average information available\n"); + else { + (void)printf(", load averages:"); + for (i = 0; i < (sizeof(avenrun) / sizeof(avenrun[0])); i++) { + if (i > 0) + (void)printf(","); + (void)printf(" %.2f", avenrun[i]); + } + (void)printf("\n"); + } +} + +static struct stat * +ttystat(line) + char *line; +{ + static struct stat sb; + char ttybuf[MAXPATHLEN]; + + (void)snprintf(ttybuf, sizeof(ttybuf), "%s/%s", _PATH_DEV, line); + if (stat(ttybuf, &sb)) + return (NULL); + return (&sb); +} + +static void +usage(wcmd) + int wcmd; +{ + if (wcmd) + (void)fprintf(stderr, + "usage: w: [-hin] [-M core] [-N system] [user]\n"); + else + (void)fprintf(stderr, "uptime\n"); + exit(1); +} diff --git a/whereis/Makefile b/whereis/Makefile new file mode 100644 index 0000000..c988af7 --- /dev/null +++ b/whereis/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = whereis + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = whereis.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble whereis.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/whereis/Makefile.postamble b/whereis/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/whereis/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/whereis/Makefile.preamble b/whereis/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/whereis/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/whereis/PB.project b/whereis/PB.project new file mode 100644 index 0000000..1efa203 --- /dev/null +++ b/whereis/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (whereis.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, whereis.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = whereis; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/whereis/whereis.1 b/whereis/whereis.1 new file mode 100644 index 0000000..22dfb28 --- /dev/null +++ b/whereis/whereis.1 @@ -0,0 +1,66 @@ +.\" $NetBSD: whereis.1,v 1.7 1998/02/06 06:20:06 perry Exp $ +.\" +.\" Copyright (c) 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)whereis.1 8.3 (Berkeley) 4/27/95 +.\" +.Dd April 27, 1995 +.Dt WHEREIS 1 +.Os BSD 3 +.Sh NAME +.Nm whereis +.Nd locate programs +.Sh SYNOPSIS +.Nm +.Op Ar program ... +.Sh DESCRIPTION +The +.Nm +utility checks the standard binary directories for the specified programs, +printing out the paths of any it finds. +.Pp +The path searched is the string returned by the +.Xr sysctl 8 +utility for the +.Dq user.cs_path +string. +.Sh SEE ALSO +.Xr sysctl 8 +.Sh COMPATIBILITY +The historic flags and arguments for the +.Nm +utility are no longer available in this version. +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . diff --git a/whereis/whereis.c b/whereis/whereis.c new file mode 100644 index 0000000..680f1f3 --- /dev/null +++ b/whereis/whereis.c @@ -0,0 +1,128 @@ +/* $NetBSD: whereis.c,v 1.8 1997/10/20 02:22:55 mrg Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)whereis.c 8.3 (Berkeley) 5/4/95"; +#endif +__RCSID("$NetBSD: whereis.c,v 1.8 1997/10/20 02:22:55 mrg Exp $"); +#endif /* not lint */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +void usage __P((void)); +int main __P((int, char *[])); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + struct stat sb; + size_t len; + int ch, sverrno, mib[2]; + char *p, *t, *std, path[MAXPATHLEN]; + + while ((ch = getopt(argc, argv, "")) != -1) + switch (ch) { + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc == 0) + usage(); + + /* Retrieve the standard path. */ + mib[0] = CTL_USER; + mib[1] = USER_CS_PATH; + if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1) + return (-1); + if (len == 0) + err(1, "user_cs_path: sysctl: zero length\n"); + if ((std = malloc(len)) == NULL) + err(1, "%s", ""); + if (sysctl(mib, 2, std, &len, NULL, 0) == -1) { + sverrno = errno; + free(std); + errno = sverrno; + err(1, "sysctl: user_cs_path"); + } + + /* For each path, for each program... */ + for (; *argv; ++argv) + for (p = std;; *p++ = ':') { + t = p; + if ((p = strchr(p, ':')) != NULL) { + *p = '\0'; + if (t == p) + t = "."; + } else + if (strlen(t) == 0) + t = "."; + (void)snprintf(path, sizeof(path), "%s/%s", t, *argv); + if (!stat(path, &sb)) + (void)printf("%s\n", path); + if (p == NULL) + break; + } + + return (0); +} + +void +usage() +{ + + (void)fprintf(stderr, "usage: whereis program [...]\n"); + exit (1); +} diff --git a/which/Makefile b/which/Makefile new file mode 100644 index 0000000..21a2a4a --- /dev/null +++ b/which/Makefile @@ -0,0 +1,49 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = which + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +OTHERLINKED = which.csh + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble which.1 + +OTHERLINKEDOFILES = which.o + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/which/Makefile.postamble b/which/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/which/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/which/Makefile.preamble b/which/Makefile.preamble new file mode 100644 index 0000000..ec3a5ea --- /dev/null +++ b/which/Makefile.preamble @@ -0,0 +1,3 @@ +SHELLTOOL = which.csh + +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/which/PB.project b/which/PB.project new file mode 100644 index 0000000..2cb830a --- /dev/null +++ b/which/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (which.csh); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, which.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = which; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/which/which.1 b/which/which.1 new file mode 100644 index 0000000..5353cdd --- /dev/null +++ b/which/which.1 @@ -0,0 +1,75 @@ +.\" $NetBSD: which.1,v 1.4 1997/10/20 03:19:23 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1991 Regents of the University of California. +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" from: @(#)which.1 6.3 (Berkeley) 4/23/91 +.\" $NetBSD: which.1,v 1.4 1997/10/20 03:19:23 lukem Exp $ +.\" +.Dd April 23, 1991 +.Dt WHICH 1 +.Os BSD 3 +.Sh NAME +.Nm which +.Nd "locate a program file including aliases and paths" +.Pq Xr csh 1 +only) +.Sh SYNOPSIS +.Nm +.Op Ar name +.Ar ... +.Sh DESCRIPTION +.Nm +takes a list of names and looks for the files which would be +executed had these names been given as commands. +Each argument is expanded if it is aliased, +and searched for along the user's path. +Both aliases and path are taken from the user's +.Pa \&.cshrc +file. +.Sh FILES +.Bl -tag -width ~/\&.cshrc +.It Pa ~/\&.cshrc +source of aliases and path values +.El +.Sh DIAGNOSTICS +A diagnostic is given for names which are aliased to more than a single +word, +or if an executable file with the argument name was not found in the path. +.Sh BUGS +Must be executed by a +.Xr csh 1 , +or some other shell which knows about aliases. +.Sh HISTORY +The +.Nm +command appeared in +.Bx 3.0 . diff --git a/which/which.csh b/which/which.csh new file mode 100644 index 0000000..5295deb --- /dev/null +++ b/which/which.csh @@ -0,0 +1,75 @@ +#!/bin/csh +# +# DO NOT USE "csh -f" +# +# Copyright (c) 1983 The Regents of the University of California. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the University of +# California, Berkeley and its contributors. +# 4. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# @(#)which.csh 5.5 (Berkeley) 4/18/91 +# + +# which : tells you which program you get +# +set prompt = "% " +set noglob +foreach arg ( $argv ) + set alius = `alias $arg` + switch ( $#alius ) + case 0 : + breaksw + case 1 : + set arg = $alius[1] + breaksw + default : + echo ${arg}: " " aliased to $alius + continue + endsw + unset found + if ( $arg:h != $arg:t ) then + if ( -e $arg ) then + echo $arg + else + echo $arg not found + endif + continue + else + foreach i ( $path ) + if ( -x $i/$arg && ! -d $i/$arg ) then + echo $i/$arg + set found + break + endif + end + endif + if ( ! $?found ) then + echo no $arg in $path + endif +end diff --git a/who/Makefile b/who/Makefile new file mode 100644 index 0000000..b29c433 --- /dev/null +++ b/who/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = who + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = who.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble who.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/who/Makefile.postamble b/who/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/who/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/who/Makefile.preamble b/who/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/who/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/who/PB.project b/who/PB.project new file mode 100644 index 0000000..d50d72e --- /dev/null +++ b/who/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (who.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, who.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = who; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/who/who.1 b/who/who.1 new file mode 100644 index 0000000..22ccda5 --- /dev/null +++ b/who/who.1 @@ -0,0 +1,134 @@ +.\" $NetBSD: who.1,v 1.9 1997/10/20 03:20:28 lukem Exp $ +.\" +.\" Copyright (c) 1986, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)who.1 8.2 (Berkeley) 12/30/93 +.\" +.Dd December 6, 1994 +.Dt WHO 1 +.Os +.Sh NAME +.Nm who +.Nd display who is logged in +.Sh SYNOPSIS +.Nm +.Op Fl mTuH +.Op Ar file +.Nm "" +.Ar am i +.Sh DESCRIPTION +The +.Nm +utility displays a list of all users currently logged on, showing for +each user the login name, tty name, the date and time of login, and +hostname if not local. +.Pp +Available options: +.Pp +.Bl -tag -width file +.It Fl m +Only print information about the current terminal. This is the +.Tn POSIX +way of saying +.Nm +.Ar am i . +.It Fl T +Print a character after the user name indicating the state of the +terminal line: +.Sq + +if the terminal is writable; +.Sq - +if it is not; +and +.Sq ? +if a bad line is encountered. +.It Fl u +Print the idle time for each user. +.It Fl H +Write column headings above the regular output. +.It Ar \&am I +Returns the invoker's real user name. +.It Ar file +By default, +.Nm +gathers information from the file +.Pa /var/run/utmp . +An alternative +.Ar file +may be specified which is usually +.Pa /var/log/wtmp +(or +.Pa /var/log/wtmp.[0-6] +depending on site policy as +.Pa wtmp +can grow quite large and daily versions may or may not +be kept around after compression by +.Xr ac 8 ) . +The +.Pa wtmp +file contains a record of every login, logout, +crash, shutdown and date change +since +.Pa wtmp +was last truncated or +created. +.El +.Pp +If +.Pa /var/log/wtmp +is being used as the file, the user name may be empty +or one of the special characters '|', '}' and '~'. Logouts produce +an output line without any user name. For more information on the +special characters, see +.Xr utmp 5 . +.Sh FILES +.Bl -tag -width /var/log/wtmp.[0-6] -compact +.It Pa /var/run/utmp +.It Pa /var/log/wtmp +.It Pa /var/log/wtmp.[0-6] +.El +.Sh SEE ALSO +.Xr last 1 , +.Xr mesg 1 , +.Xr users 1 , +.Xr getuid 2 , +.Xr utmp 5 +.Sh STANDARDS +The +.Nm +utility is expected to conform to +.St -p1003.2-92 . +.Sh HISTORY +A +.Nm +utility appeared in +.At v6 . diff --git a/who/who.c b/who/who.c new file mode 100644 index 0000000..f045888 --- /dev/null +++ b/who/who.c @@ -0,0 +1,273 @@ +/* $NetBSD: who.c,v 1.6 1997/10/20 03:20:29 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Michael Fischbein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT( +"@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)who.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: who.c,v 1.6 1997/10/20 03:20:29 lukem Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void output __P((struct utmp *)); +void output_labels __P((void)); +void who_am_i __P((FILE *)); +FILE *file __P((char *)); +void usage __P((void)); + +int show_term; /* show term state */ +int show_idle; /* show idle time */ + +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char **argv; +{ + struct utmp usr; + FILE *ufp; + int c, only_current_term, show_labels; + + setlocale(LC_ALL, ""); + + only_current_term = show_term = show_idle = show_labels = 0; + while ((c = getopt(argc, argv, "mTuH")) != -1) { + switch (c) { + case 'm': + only_current_term = 1; + break; + case 'T': + show_term = 1; + break; + case 'u': + show_idle = 1; + break; + case 'H': + show_labels = 1; + break; + default: + usage(); + /* NOTREACHED */ + } + } + argc -= optind; + argv += optind; + + if (chdir("/dev")) { + err(1, "cannot change directory to /dev"); + /* NOTREACHED */ + } + + if (show_labels) + output_labels(); + + switch (argc) { + case 0: /* who */ + ufp = file(_PATH_UTMP); + + if (only_current_term) { + who_am_i(ufp); + } else { + /* only entries with both name and line fields */ + while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1) + if (*usr.ut_name && *usr.ut_line) + output(&usr); + } + break; + case 1: /* who utmp_file */ + ufp = file(*argv); + + if (only_current_term) { + who_am_i(ufp); + } else { + /* all entries */ + while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1) + output(&usr); + } + break; + case 2: /* who am i */ + ufp = file(_PATH_UTMP); + who_am_i(ufp); + break; + default: + usage(); + /* NOTREACHED */ + } + exit(0); +} + +void +who_am_i(ufp) + FILE *ufp; +{ + struct utmp usr; + struct passwd *pw; + char *p; + char *t; + + /* search through the utmp and find an entry for this tty */ + if ((p = ttyname(0)) != NULL) { + /* strip any directory component */ + if ((t = strrchr(p, '/')) != NULL) + p = t + 1; + while (fread((char *)&usr, sizeof(usr), 1, ufp) == 1) + if (usr.ut_name && !strcmp(usr.ut_line, p)) { + output(&usr); + return; + } + /* well, at least we know what the tty is */ + (void)strncpy(usr.ut_line, p, UT_LINESIZE); + } else + (void)strcpy(usr.ut_line, "tty??"); + + pw = getpwuid(getuid()); + (void)strncpy(usr.ut_name, pw ? pw->pw_name : "?", UT_NAMESIZE); + (void)time(&usr.ut_time); + *usr.ut_host = '\0'; + output(&usr); +} + +void +output(up) + struct utmp *up; +{ + struct stat sb; + char line[sizeof (up->ut_line) + 1]; + char state; + static time_t now = 0; + time_t idle; + + state = '?'; + idle = 0; + + if (show_term || show_idle) { + if (now == 0) + time(&now); + + strncpy(line, up->ut_line, sizeof (up->ut_line)); + line[sizeof (up->ut_line)] = '\0'; + + if (stat(line, &sb) == 0) { + state = (sb.st_mode & 020) ? '+' : '-'; + idle = now - sb.st_atime; + } + + } + + (void)printf("%-*.*s ", UT_NAMESIZE, UT_NAMESIZE, up->ut_name); + + if (show_term) { + (void)printf("%c ", state); + } + + (void)printf("%-*.*s ", UT_LINESIZE, UT_LINESIZE, up->ut_line); + (void)printf("%.12s ", ctime(&up->ut_time) + 4); + + if (show_idle) { + if (idle < 60) + (void)printf(" . "); + else if (idle < (24 * 60 * 60)) + (void)printf("%02ld:%02ld ", + (long)(idle / (60 * 60)), + (long)(idle % (60 * 60)) / 60); + else + (void)printf(" old "); + } + + if (*up->ut_host) + printf("\t(%.*s)", UT_HOSTSIZE, up->ut_host); + (void)putchar('\n'); +} + +void +output_labels() +{ + (void)printf("%-*.*s ", UT_NAMESIZE, UT_NAMESIZE, "USER"); + + if (show_term) + (void)printf("S "); + + (void)printf("%-*.*s ", UT_LINESIZE, UT_LINESIZE, "LINE"); + (void)printf("WHEN "); + + if (show_idle) + (void)printf("IDLE "); + + (void)printf("\t%.*s", UT_HOSTSIZE, "FROM"); + + (void)putchar('\n'); +} + +FILE * +file(name) + char *name; +{ + FILE *ufp; + + if (!(ufp = fopen(name, "r"))) { + err(1, "%s", name); + /* NOTREACHED */ + } + return (ufp); +} + +void +usage() +{ + (void)fprintf(stderr, "usage: who [-mTuH] [ file ]\n who am i\n"); + exit(1); +} diff --git a/window/Makefile b/window/Makefile new file mode 100644 index 0000000..674ab40 --- /dev/null +++ b/window/Makefile @@ -0,0 +1,66 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = window + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = alias.h char.h context.h defs.h lcmd.h local.h parser.h\ + token.h tt.h value.h var.h ww.h xx.h window_string.h + +CFILES = char.c cmd.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c\ + cmd7.c compress.c context.c error.c lcmd.c lcmd1.c lcmd2.c\ + main.c mloop.c parser1.c parser2.c parser3.c parser4.c\ + parser5.c scanner.c startup.c string.c ttf100.c ttgeneric.c\ + tth19.c tth29.c ttinit.c ttoutput.c tttermcap.c tttvi925.c\ + ttwyse60.c ttwyse75.c ttzapple.c ttzentec.c var.c win.c\ + wwadd.c wwalloc.c wwbox.c wwchild.c wwclose.c wwclreol.c\ + wwclreos.c wwcursor.c wwdata.c wwdelchar.c wwdelete.c\ + wwdelline.c wwdump.c wwend.c wwenviron.c wwerror.c wwflush.c\ + wwframe.c wwgets.c wwinit.c wwinschar.c wwinsline.c\ + wwiomux.c wwlabel.c wwmisc.c wwmove.c wwopen.c wwprintf.c\ + wwpty.c wwputc.c wwputs.c wwredraw.c wwredrawwin.c wwrint.c\ + wwscroll.c wwsize.c wwspawn.c wwsuspend.c wwterminfo.c\ + wwtty.c wwunframe.c wwupdate.c wwwrite.c xx.c xxflush.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble README\ + window.1 windowrc + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + +NEXTSTEP_PB_CFLAGS = -Wno-error + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/window/Makefile.postamble b/window/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/window/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/window/Makefile.preamble b/window/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/window/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/window/PB.project b/window/PB.project new file mode 100644 index 0000000..b18adac --- /dev/null +++ b/window/PB.project @@ -0,0 +1,131 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = ( + alias.h, + char.h, + context.h, + defs.h, + lcmd.h, + local.h, + parser.h, + token.h, + tt.h, + value.h, + var.h, + ww.h, + xx.h, + window_string.h + ); + OTHER_LINKED = ( + char.c, + cmd.c, + cmd1.c, + cmd2.c, + cmd3.c, + cmd4.c, + cmd5.c, + cmd6.c, + cmd7.c, + compress.c, + context.c, + error.c, + lcmd.c, + lcmd1.c, + lcmd2.c, + main.c, + mloop.c, + parser1.c, + parser2.c, + parser3.c, + parser4.c, + parser5.c, + scanner.c, + startup.c, + string.c, + ttf100.c, + ttgeneric.c, + tth19.c, + tth29.c, + ttinit.c, + ttoutput.c, + tttermcap.c, + tttvi925.c, + ttwyse60.c, + ttwyse75.c, + ttzapple.c, + ttzentec.c, + var.c, + win.c, + wwadd.c, + wwalloc.c, + wwbox.c, + wwchild.c, + wwclose.c, + wwclreol.c, + wwclreos.c, + wwcursor.c, + wwdata.c, + wwdelchar.c, + wwdelete.c, + wwdelline.c, + wwdump.c, + wwend.c, + wwenviron.c, + wwerror.c, + wwflush.c, + wwframe.c, + wwgets.c, + wwinit.c, + wwinschar.c, + wwinsline.c, + wwiomux.c, + wwlabel.c, + wwmisc.c, + wwmove.c, + wwopen.c, + wwprintf.c, + wwpty.c, + wwputc.c, + wwputs.c, + wwredraw.c, + wwredrawwin.c, + wwrint.c, + wwscroll.c, + wwsize.c, + wwspawn.c, + wwsuspend.c, + wwterminfo.c, + wwtty.c, + wwunframe.c, + wwupdate.c, + wwwrite.c, + xx.c, + xxflush.c + ); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, README, window.1, windowrc); + PRECOMPILED_HEADERS = (); + PROJECT_HEADERS = (); + PUBLIC_HEADERS = (); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_COMPILEROPTIONS = "-Wno-error"; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = window; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/window/README b/window/README new file mode 100644 index 0000000..42d45b3 --- /dev/null +++ b/window/README @@ -0,0 +1,199 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)README 8.1 (Berkeley) 6/6/93 + */ + +Compilation notes: + + Compiler options: + + BYTE_ORDER (used only in ww.h) + It should already be defined in machine/endian.h. + The code knows about BIG_ENDIAN, LITTLE_ENDIAN, and PDP_ENDIAN. + It only cares about byte order in words, so PDP_ENDIAN + is the same as LITTLE_ENDIAN. + OLD_TTY + If you don't have Posix termios, then define this. + VMIN_BUG + Even if you have Posix termios, define this if the MIN and TIME + feature in noncanonical mode doesn't work correctly. + + Ok, there's another one, STR_DEBUG. It turns on consistency checks + in the string allocator. It's been left on since performace doesn't + seem to suffer. There's an abort() somewhere when an inconsistency + is found. It hasn't happened in years. + + The file local.h contains locally tunable constants. + + The makefile used to be updated with mkmf; it has been changed +at various times to use cpp -M and, currently, mkdep. The only library +it needs is termcap. + + Window, as is, only runs on 4.3 (or later) machines. + + On 4.2 machines, at least these modifications must be done: + + delete uses of window size ioctls: TIOCGWINSZ, TIOCSWINSZ, + struct winsize + add to ww.h + typedef int fd_set; + #define FD_ZERO(s) (*(s) = 0) + #define FD_SET(b, s) (*(s) |= 1 << (b)) + #define FD_ISSET(b, s) (*(s) & 1 << (b)) + add to ww.h + #define sigmask(s) (1 << (s) - 1) + + +A few notes about the internals: + + The window package. Windows are opened by calling wwopen(). +Wwwrite() is the primitive for writing to windows. Wwputc(), wwputs(), +and wwprintf() are also supported. Some of the outputs to windows are +delayed. Wwupdate() updates the terminal to match the internal screen +buffer. Wwspawn() spawns a child process on the other end of a window, +with its environment tailored to the window. Visible windows are +doubly linked in the order of their overlap. Wwadd() inserts a window +into the list at a given place. Wwdelete() deletes it. Windows not in +the list are not visible, though wwwrite() still works. Window was +written before the days of X and Sunview, so some of the terminology +is not standard. + + Most functions return -1 on error. Wwopen() returns the null +pointer. An error number is saved in wwerrno. Wwerror() returns an +error string based on wwerrno suitable for printing. + + The terminal drivers perform all output to the physical terminal, +including special functions like character and line insertion and +deletion. The window package keeps a list of known terminals. At +initialization time, the terminal type is matched against the list to +find the right terminal driver to use. The last driver, the generic +driver, matches all terminals and uses the termcap database. The +interface between the window package the terminal driver is the `tt' +structure. It contains pointers to functions to perform special +functions and terminal output, as well as flags about the +characteristics of the terminal. Most of these ideas are borrowed +from the Maryland window package, which in turn is based on Goslin's +Emacs. + + The IO system is semi-synchronous. Terminal input is signal +driven, and everything else is done synchronously with a single +select(). It is roughly event-driven, though not in a clean way. + + Normally, in both conversation mode and command mode, window +sleeps in a select() in wwiomux() waiting for data from the +pseudo-terminals. At the same time, terminal input causes SIGIO which +is caught by wwrint(). The select() returns when at least one of the +pseudo-terminals becomes ready for reading. + + Wwrint() is the interrupt handler for tty input. It reads input +into a linear buffer accessed through four pointers: + + +-------+--------------+----------------+ + | empty | data | empty | + +-------+--------------+----------------+ + ^ ^ ^ ^ + | | | | + wwib wwibp wwibq wwibe + +Wwrint() appends characters at the end and increments wwibq (*wwibq++ += c), and characters are taken off the buffer at wwibp using the +wwgetc() and wwpeekc() macros. As is the convention in C, wwibq +and wwibe point to one position beyond the end. In addition, +wwrint() will do a longjmp(wwjmpbuf) if wwsetjmp is true. This is +used by wwiomux() to interrupt the select() which would otherwise +resume after the interrupt. (Actually, I hear this is not true, +but the longjmp feature is used to avoid a race condition as well. +Anyway, it means I didn't have to depend on a feature in a +daily-changing kernel, but that's another story.) The macro +wwinterrupt() returns true if the input buffer is non-empty. +Wwupdate(), wwwrite(), and wwiomux() check this condition and will +return at the first convenient opportunity when it becomes true. +In the case of wwwrite(), the flag ww_nointr in the window structure +overrides this. This feature allows the user to interrupt lengthy +outputs safely. The structure of the input buffer is designed to +avoid race conditions without blocking interrupts. + + Actually, wwsetjmp and wwinterrupt() are part of a software +interrupt scheme used by the two interrupt catchers wwrint() and +wwchild(). Asserting the interrupt lets the synchronous parts of +the program know that there's an interesting asynchronous condition +(i.e., got a keyboard character, or a child process died) that they +might want to process before anything else. The synchronous routines +can check for this condition with wwinterrupt() or by arranging +that a longjmp() be done. + + Wwiomux() copies pseudo-terminal output into their corresponding +windows. Without anything to do, it blocks in a select(), waiting for +read ready on pseudo-terminals. Reads are done into per-window buffers +in the window structures. When there is at least one buffer non-empty, +wwiomux() finds the top most of these windows and writes it using +wwwrite(). Then the process is repeated. A non-blocking select() is +done after a wwwrite() to pick up any output that may have come in +during the write, which may take a long time. Specifically, we use +this to stop output or flush buffer when a pseudo-terminal tells us to +(we use pty packet mode). The select() blocks only when all of the +windows' buffers are empty. A wwupdate() is done prior to this, which +is the only time the screen is guaranteed to be completely up to date. +Wwiomux() loops until wwinterrupt() becomes true. + + The top level routine for all this is mloop(). In conversation +mode, it simply calls wwiomux(), which only returns when input is +available. The input buffer is then written to the pseudo-terminal of +the current window. If the escape character is found in the input, +command mode is entered. Otherwise, the process is repeated. In +command mode, control is transferred to docmd() which returns only when +conversation mode is reentered. Docmd() and other command processing +routines typically wait for input in a loop: + + while (wwpeekc() < 0) + wwiomux(); + +When the loop terminates, wwgetc() is used to read the input buffer. + + Output to the physical terminal is handled by the lowest level +routines of the window package, in the files ttoutput.c and tt.h. The +standard IO package is not used, to get better control over buffering +and to use non-blocking reads in wwrint(). The buffer size is set to +approximately one second of output time, based on the baudrate. + + The result of all this complexity is faster response time, +especially in output stopping and flushing. Wwwrite() checks +wwinterrupt() after every line. It also calls wwupdate() for each line +it writes. The output buffer is limited to one second of output time. +Thus, there is usually only a delay of one to two lines plus one second +after a ^C or ^S. Also, commands that produce lengthy output can be +aborted without actually showing all of it on the terminal. (Try the +'?' command followed by escape immediately.) diff --git a/window/alias.h b/window/alias.h new file mode 100644 index 0000000..00928a2 --- /dev/null +++ b/window/alias.h @@ -0,0 +1,58 @@ +/* $NetBSD: alias.h,v 1.3 1995/09/28 10:33:59 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)alias.h 8.1 (Berkeley) 6/6/93 + */ + +#ifndef EXTERN +#define EXTERN extern +#endif + +#define alias var +#define a_name r_name +#define a_buf r_val.v_str +#define a_flags r_val.v_type + + /* a_flags bits, must not interfere with v_type values */ +#define A_INUSE 0x010 /* already inuse */ + +#define alias_set(n, s) var_setstr1(&alias_head, n, s) +#define alias_walk(f, a) var_walk1(alias_head, f, a) +#define alias_unset(n) var_unset1(&alias_head, n) +#define alias_lookup(n) (*var_lookup1(&alias_head, n)) + +EXTERN struct var *alias_head; diff --git a/window/char.c b/window/char.c new file mode 100644 index 0000000..c7a43a3 --- /dev/null +++ b/window/char.c @@ -0,0 +1,157 @@ +/* $NetBSD: char.c,v 1.4 1997/11/21 08:35:43 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)char.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: char.c,v 1.4 1997/11/21 08:35:43 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "char.h" + +char _cmap[] = { + _C|_U, _C|_U, _C|_U, _C|_U, /* ^@ - ^C */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^D - ^G */ + _C, _C|_P, _C, _C|_U, /* ^H - ^K */ + _C|_U, _C, _C|_U, _C|_U, /* ^L - ^O */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^P - ^S */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^T - ^W */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^U - ^[ */ + _C|_U, _C|_U, _C|_U, _C|_U, /* ^\ - ^_ */ + + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _P|_U, + _P|_U, _P|_U, _P|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U, + _C|_U, _C|_U, _C|_U, _C|_U +}; + +char *_unctrl[] = { + "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", + "^H", "^I", "^J", "^K", "^L", "^M", "^N", "^O", + "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W", + "^X", "^Y", "^Z", "^[", "^\\", "^]", "^^", "^_", + " ", "!", "\"", "#", "$", "%", "&", "'", + "(", ")", "*", "+", ",", "-", ".", "/", + "0", "1", "2", "3", "4", "5", "6", "7", + "8", "9", ":", ";", "<", "=", ">", "?", + "@", "A", "B", "C", "D", "E", "F", "G", + "H", "I", "J", "K", "L", "M", "N", "O", + "P", "Q", "R", "S", "T", "U", "V", "W", + "X", "Y", "Z", "[", "\\", "]", "^", "_", + "`", "a", "b", "c", "d", "e", "f", "g", + "h", "i", "j", "k", "l", "m", "n", "o", + "p", "q", "r", "s", "t", "u", "v", "w", + "x", "y", "z", "{", "|", "}", "~", "^?", + "\\200","\\201","\\202","\\203","\\204","\\205","\\206","\\207", + "\\210","\\211","\\212","\\213","\\214","\\215","\\216","\\217", + "\\220","\\221","\\222","\\223","\\224","\\225","\\226","\\227", + "\\230","\\231","\\232","\\233","\\234","\\235","\\236","\\237", + "\\240","\\241","\\242","\\243","\\244","\\245","\\246","\\247", + "\\250","\\251","\\252","\\253","\\254","\\255","\\256","\\257", + "\\260","\\261","\\262","\\263","\\264","\\265","\\266","\\267", + "\\270","\\271","\\272","\\273","\\274","\\275","\\276","\\277", + "\\300","\\301","\\302","\\303","\\304","\\305","\\306","\\307", + "\\310","\\311","\\312","\\313","\\314","\\315","\\316","\\317", + "\\320","\\321","\\322","\\323","\\324","\\325","\\326","\\327", + "\\330","\\331","\\332","\\333","\\334","\\335","\\336","\\337", + "\\340","\\341","\\342","\\343","\\344","\\345","\\346","\\347", + "\\350","\\351","\\352","\\353","\\354","\\355","\\356","\\357", + "\\360","\\361","\\362","\\363","\\364","\\365","\\366","\\367", + "\\370","\\371","\\372","\\373","\\374","\\375","\\376","\\377" +}; diff --git a/window/char.h b/window/char.h new file mode 100644 index 0000000..28c1fc5 --- /dev/null +++ b/window/char.h @@ -0,0 +1,66 @@ +/* $NetBSD: char.h,v 1.3 1995/09/28 10:34:01 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)char.h 8.1 (Berkeley) 6/6/93 + */ + +/* + * Macros and things to deal with control characters. + * + * Unctrl() is just like the standard function, except we don't want + * to include curses. + * Isctrl() returns true for all characters less than space and + * greater than or equal to delete. + * Isprt() is tab and all characters not isctrl(). It's used + * by wwwrite(). + * Isunctrl() includes all characters that should be expanded + * using unctrl() by wwwrite() if ww_unctrl is set. + */ + +extern char *_unctrl[]; +extern char _cmap[]; +#define ctrl(c) (c & 0x1f) +#ifdef __APPLE__ +#undef unctrl +#endif +#define unctrl(c) (_unctrl[(unsigned char) (c)]) +#define _C 0x01 +#define _P 0x02 +#define _U 0x04 +#define isctrl(c) (_cmap[(unsigned char) (c)] & _C) +#define isprt(c) (_cmap[(unsigned char) (c)] & _P) +#define isunctrl(c) (_cmap[(unsigned char) (c)] & _U) diff --git a/window/cmd.c b/window/cmd.c new file mode 100644 index 0000000..d0b1bb9 --- /dev/null +++ b/window/cmd.c @@ -0,0 +1,316 @@ +/* $NetBSD: cmd.c,v 1.6 1998/08/25 20:59:42 ross Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd.c,v 1.6 1998/08/25 20:59:42 ross Exp $"); +#endif +#endif /* not lint */ + +#include +#include "defs.h" +#include "char.h" + +int checkproc __P((struct ww *)); + +void +docmd() +{ + int c; + struct ww *w; + char out = 0; + + while (!out && !quit) { + if ((c = wwgetc()) < 0) { + if (terse) + wwsetcursor(0, 0); + else { + wwputs("Command: ", cmdwin); + wwcurtowin(cmdwin); + } + do + wwiomux(); + while ((c = wwgetc()) < 0); + } + if (!terse) + wwputc('\n', cmdwin); + switch (c) { + default: + if (c != escapec) + break; + case 'h': case 'j': case 'k': case 'l': + case 'y': case 'p': + case ctrl('y'): + case ctrl('e'): + case ctrl('u'): + case ctrl('d'): + case ctrl('b'): + case ctrl('f'): + case ctrl('s'): + case ctrl('q'): + case ctrl('['): + if (selwin == 0) { + error("No window."); + continue; + } + } + switch (c) { + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': + if ((w = window[c - '1']) == 0) { + error("%c: No such window.", c); + break; + } + setselwin(w); + if (checkproc(selwin) >= 0) + out = 1; + break; + case '%': + if ((w = getwin()) != 0) + setselwin(w); + break; + case ctrl('^'): + if (lastselwin != 0) { + setselwin(lastselwin); + if (checkproc(selwin) >= 0) + out = 1; + } else + error("No previous window."); + break; + case 'c': + if ((w = getwin()) != 0) + closewin(w); + break; + case 'w': + c_window(); + break; + case 'm': + if ((w = getwin()) != 0) + c_move(w); + break; + case 'M': + if ((w = getwin()) != 0) + movewin(w, w->ww_alt.t, w->ww_alt.l); + break; + case 's': + if ((w = getwin()) != 0) + c_size(w); + break; + case 'S': + if ((w = getwin()) != 0) + sizewin(w, w->ww_alt.nr, w->ww_alt.nc); + break; + case 'y': + c_yank(); + break; + case 'p': + c_put(); + break; + case ':': + c_colon(); + break; + case 'h': + (void) wwwrite(selwin, "\b", 1); + break; + case 'j': + (void) wwwrite(selwin, "\n", 1); + break; + case 'k': + (void) wwwrite(selwin, "\033A", 2); + break; + case 'l': + (void) wwwrite(selwin, "\033C", 2); + break; + case ctrl('e'): + wwscroll(selwin, 1); + break; + case ctrl('y'): + wwscroll(selwin, -1); + break; + case ctrl('d'): + wwscroll(selwin, selwin->ww_w.nr / 2); + break; + case ctrl('u'): + wwscroll(selwin, - selwin->ww_w.nr / 2); + break; + case ctrl('f'): + wwscroll(selwin, selwin->ww_w.nr); + break; + case ctrl('b'): + wwscroll(selwin, - selwin->ww_w.nr); + break; + case ctrl('s'): + stopwin(selwin); + break; + case ctrl('q'): + startwin(selwin); + break; + case ctrl('l'): + wwredraw(); + break; + case '?': + c_help(); + break; + case ctrl('['): + if (checkproc(selwin) >= 0) + out = 1; + break; + case ctrl('z'): + wwsuspend(); + break; + case 'q': + c_quit(); + break; + /* debugging stuff */ + case '&': + if (debug) { + c_debug(); + break; + } + default: + if (c == escapec) { + if (checkproc(selwin) >= 0) { + (void) write(selwin->ww_pty, + &escapec, 1); + out = 1; + } + } else { + if (!terse) + wwbell(); + error("Type ? for help."); + } + } + } + if (!quit) + setcmd(0); +} + +struct ww * +getwin() +{ + int c; + struct ww *w = 0; + + if (!terse) + wwputs("Which window? ", cmdwin); + wwcurtowin(cmdwin); + while ((c = wwgetc()) < 0) + wwiomux(); + if (debug && c == 'c') + w = cmdwin; + else if (debug && c == 'f') + w = framewin; + else if (debug && c == 'b') + w = boxwin; + else if (c >= '1' && c < NWINDOW + '1') + w = window[c - '1']; + else if (c == '+') + w = selwin; + else if (c == '-') + w = lastselwin; + if (w == 0) + wwbell(); + if (!terse) + wwputc('\n', cmdwin); + return w; +} + +int +checkproc(w) + struct ww *w; +{ + if (w->ww_state != WWS_HASPROC) { + error("No process in window."); + return -1; + } + return 0; +} + +void +setcmd(new) + char new; +{ + if (new && !incmd) { + if (!terse) + wwadd(cmdwin, &wwhead); + if (selwin != 0) + wwcursor(selwin, 1); + wwcurwin = 0; + } else if (!new && incmd) { + if (!terse) { + wwdelete(cmdwin); + reframe(); + } + if (selwin != 0) + wwcursor(selwin, 0); + wwcurwin = selwin; + } + incmd = new; +} + +void +setterse(new) + char new; +{ + if (incmd) { + if (new && !terse) { + wwdelete(cmdwin); + reframe(); + } else if (!new && terse) + wwadd(cmdwin, &wwhead); + } + terse = new; +} + +/* + * Set the current window. + */ +void +setselwin(w) + struct ww *w; +{ + if (selwin == w) + return; + if (selwin != 0) + lastselwin = selwin; + if ((selwin = w) != 0) + front(selwin, 1); +} diff --git a/window/cmd1.c b/window/cmd1.c new file mode 100644 index 0000000..f7ed760 --- /dev/null +++ b/window/cmd1.c @@ -0,0 +1,182 @@ +/* $NetBSD: cmd1.c,v 1.5 1997/11/21 08:35:46 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd1.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd1.c,v 1.5 1997/11/21 08:35:46 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "char.h" + +void +c_window() +{ + int col, row, xcol, xrow; + int id; + + if ((id = findid()) < 0) + return; + if (!terse) + wwputs("New window (upper left corner): ", cmdwin); + col = 0; + row = 1; + wwadd(boxwin, framewin->ww_back); + for (;;) { + wwbox(boxwin, row - 1, col - 1, 3, 3); + wwsetcursor(row, col); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row, &col, row > 1, 0, + wwnrow - 1, wwncol - 1)) { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + if (!terse) + wwputs("\nNew window (lower right corner): ", cmdwin); + xcol = col; + xrow = row; + for (;;) { + wwbox(boxwin, row - 1, col - 1, + xrow - row + 3, xcol - col + 3); + wwsetcursor(xrow, xcol); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1)) + { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + wwdelete(boxwin); + if (!terse) + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + (void) openwin(id, row, col, xrow-row+1, xcol-col+1, default_nline, + (char *) 0, WWT_PTY, WWU_HASFRAME, default_shellfile, + default_shell); +} + +int +getpos(row, col, minrow, mincol, maxrow, maxcol) + int *row, *col; + int minrow, mincol; + int maxrow, maxcol; +{ + static int scount; + int count; + int c; + int oldrow = *row, oldcol = *col; + + while ((c = wwgetc()) >= 0) { + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + scount = scount * 10 + c - '0'; + continue; + } + count = scount ? scount : 1; + scount = 0; + switch (c) { + case 'h': + if ((*col -= count) < mincol) + *col = mincol; + break; + case 'H': + *col = mincol; + break; + case 'l': + if ((*col += count) > maxcol) + *col = maxcol; + break; + case 'L': + *col = maxcol; + break; + case 'j': + if ((*row += count) > maxrow) + *row = maxrow; + break; + case 'J': + *row = maxrow; + break; + case 'k': + if ((*row -= count) < minrow) + *row = minrow; + break; + case 'K': + *row = minrow; + break; + case ctrl('['): + if (!terse) + wwputs("\nCancelled. ", cmdwin); + return 3; + case '\r': + return 2; + default: + if (!terse) + wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin); + wwbell(); + } + } + return oldrow != *row || oldcol != *col; +} diff --git a/window/cmd2.c b/window/cmd2.c new file mode 100644 index 0000000..6cffcfc --- /dev/null +++ b/window/cmd2.c @@ -0,0 +1,167 @@ +/* $NetBSD: cmd2.c,v 1.4 1997/11/21 08:35:47 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd2.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd2.c,v 1.4 1997/11/21 08:35:47 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" + +char *help_shortcmd[] = { + "# Select window # and return to conversation mode", + "%# Select window # but stay in command mode", + "escape Return to conversation mode without changing window", + "^^ Return to conversation mode and change to previous window", + "c# Close window #", + "w Open a new window", + "m# Move window #", + "M# Move window # to its previous position", + "s# Change the size of window #", + "S# Change window # to its previous size", + "^Y Scroll up one line", + "^E Scroll down one line", + "^U Scroll up half a window", + "^D Scroll down half a window", + "^B Scroll up a full window", + "^F Scroll down a full window", + "h Move cursor left", + "j Move cursor down", + "k Move cursor up", + "l Move cursor right", + "y Yank", + "p Put", + "^S Stop output in current window", + "^Q Restart output in current window", + "^L Redraw screen", + "^Z Suspend", + "q Quit", + ": Enter a long command", + 0 +}; + +char *help_longcmd[] = { + ":alias name string ... Make `name' an alias for `string ...'", + ":alias Show all aliases", + ":close # ... Close windows", + ":close all Close all windows", + ":cursor modes Set the cursor modes", + ":echo # string ... Print `string ...' in window #", + ":escape c Set escape character to `c'", + ":foreground # flag Make # a foreground window, if `flag' is true", + ":label # string Set label of window # to `string'", + ":list List all open windows", + ":default_nline lines Set default window buffer size to `lines'", + ":default_shell string ...", + " Set default shell to `string ...'", + ":default_smooth flag Set default smooth scroll flag", + ":select # Select window #", + ":smooth # flag Set window # to smooth scroll mode", + ":source filename Execute commands in `filename'", + ":terse flag Set terse mode", + ":unalias name Undefine `name' as an alias", + ":unset variable Deallocate `variable'", + ":variable List all variables", + ":window [row col nrow ncol nline label pty frame mapnl keepopen smooth shell]", + " Open a window at `row', `col' of size `nrow', `ncol',", + " with `nline' lines in the buffer, and `label'", + ":write # string ... Write `string ...' to window # as input", + 0 +}; + +int help_print __P((struct ww *, char *, char **)); + +void +c_help() +{ + struct ww *w; + + if ((w = openiwin(wwnrow - 3, "Help")) == 0) { + error("Can't open help window: %s.", wwerror()); + return; + } + wwprintf(w, "The escape character is %c.\n", escapec); + wwprintf(w, "(# represents one of the digits from 1 to 9.)\n\n"); + if (help_print(w, "Short commands", help_shortcmd) >= 0) + (void) help_print(w, "Long commands", help_longcmd); + closeiwin(w); +} + +int +help_print(w, name, list) + struct ww *w; + char *name; + char **list; +{ + wwprintf(w, "%s:\n\n", name); + while (*list) + switch (more(w, 0)) { + case 0: + wwputs(*list++, w); + wwputc('\n', w); + break; + case 1: + wwprintf(w, "%s: (continued)\n\n", name); + break; + case 2: + return -1; + } + return more(w, 1) == 2 ? -1 : 0; +} + +void +c_quit() +{ + char oldterse = terse; + + setterse(0); + wwputs("Really quit [yn]? ", cmdwin); + wwcurtowin(cmdwin); + while (wwpeekc() < 0) + wwiomux(); + if (wwgetc() == 'y') { + wwputs("Yes", cmdwin); + quit++; + } else + wwputc('\n', cmdwin); + setterse(!quit && oldterse); +} diff --git a/window/cmd3.c b/window/cmd3.c new file mode 100644 index 0000000..4b229c6 --- /dev/null +++ b/window/cmd3.c @@ -0,0 +1,74 @@ +/* $NetBSD: cmd3.c,v 1.4 1997/11/21 08:35:49 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd3.c,v 1.4 1997/11/21 08:35:49 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "window_string.h" + +void +setescape(esc) + char *esc; +{ + if (*esc == '^') { + if (esc[1] != 0) + escapec = esc[1] & 0x1f; + else + escapec = '^'; + } else + escapec = *esc; +} + +int +setlabel(w, label) + struct ww *w; + char *label; +{ + if (w->ww_label != 0) + str_free(w->ww_label); + if ((w->ww_label = str_cpy(label)) == 0) + return -1; + return 0; +} diff --git a/window/cmd4.c b/window/cmd4.c new file mode 100644 index 0000000..b356599 --- /dev/null +++ b/window/cmd4.c @@ -0,0 +1,64 @@ +/* $NetBSD: cmd4.c,v 1.4 1997/11/21 08:35:50 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd4.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd4.c,v 1.4 1997/11/21 08:35:50 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" + +void +c_colon() +{ + char oldterse = terse; + char buf[512]; + + setterse(0); + wwputc(':', cmdwin); + wwgets(buf, wwncol - 3, cmdwin); + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + setterse(oldterse); + if (dolongcmd(buf, (struct value *)0, 0) < 0) + error("Out of memory."); +} diff --git a/window/cmd5.c b/window/cmd5.c new file mode 100644 index 0000000..13f8b6e --- /dev/null +++ b/window/cmd5.c @@ -0,0 +1,142 @@ +/* $NetBSD: cmd5.c,v 1.5 1998/07/09 18:34:39 msaitoh Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd5.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd5.c,v 1.5 1998/07/09 18:34:39 msaitoh Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" + +/* + * Window movement. + */ + +void getminmax __P((int, int, int, int, int *, int *, int *)); + +void +c_move(w) + struct ww *w; +{ + int col, row; + int mincol, minrow; + int maxcol, maxrow; + int curcol, currow; + + if (!terse) + wwputs("New window position: ", cmdwin); + col = w->ww_w.l; + row = w->ww_w.t; + wwadd(boxwin, framewin->ww_back); + for (;;) { + wwbox(boxwin, row - 1, col - 1, w->ww_w.nr + 2, w->ww_w.nc + 2); + getminmax(row, w->ww_w.nr, 1, wwnrow, + &currow, &minrow, &maxrow); + getminmax(col, w->ww_w.nc, 0, wwncol, + &curcol, &mincol, &maxcol); + wwsetcursor(currow, curcol); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row, &col, minrow, mincol, maxrow, maxcol)) { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + wwdelete(boxwin); + if (!terse) + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + movewin(w, row, col); +} + +void +movewin(w, row, col) + struct ww *w; + int row, col; +{ + struct ww *back = w->ww_back; + + w->ww_alt.t = w->ww_w.t; + w->ww_alt.l = w->ww_w.l; + wwdelete(w); + wwmove(w, row, col); + wwadd(w, back); + reframe(); +} + +/* + * Weird stufff, don't ask. + */ +void +getminmax(x, n, a, b, curx, minx, maxx) + int x, n, a, b; + int *curx, *minx, *maxx; +{ + if (x < 0) + *curx = x + n - 1; + else + *curx = x; + + if (x <= a) + *minx = 1 - n; + else if (x <= b - n) + *minx = a; + else + *minx = b - n; + + if (x >= b - n) + *maxx = b - 1; + else if (x >= a) + *maxx = b - n; + else + *maxx = a; +} diff --git a/window/cmd6.c b/window/cmd6.c new file mode 100644 index 0000000..dce3343 --- /dev/null +++ b/window/cmd6.c @@ -0,0 +1,119 @@ +/* $NetBSD: cmd6.c,v 1.4 1997/11/21 08:35:53 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd6.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd6.c,v 1.4 1997/11/21 08:35:53 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "window_string.h" +#include "char.h" + +/* + * Debugging commands. + */ + +void debug_str __P((void)); + +void +c_debug() +{ + struct ww *w; + + if (!terse) + wwputs("[m(smap) n(ns) o(os) s(string) v(nvis) w(win)]? ", + cmdwin); + wwcurtowin(cmdwin); + while (wwpeekc() < 0) + wwiomux(); + if (!terse) + wwputc('\n', cmdwin); + switch (wwgetc()) { + case 'm': + wwdumpsmap(); + break; + case 'n': + wwdumpns(); + break; + case 'o': + wwdumpos(); + break; + case 's': + debug_str(); + break; + case 'v': + if ((w = getwin()) != 0) + wwdumpnvis(w); + break; + case 'w': + if ((w = getwin()) != 0) + wwdumpwin(w); + break; + default: + wwbell(); + } +} + +void +debug_str() +{ +#ifdef STR_DEBUG + struct ww *w; + struct string *s; + + if ((w = openiwin(wwnrow - 3, "Allocated Strings")) == 0) { + error("Can't open string window: %s.", wwerror()); + return; + } + for (s = str_head.s_forw; s != &str_head; s = s->s_forw) { + if (more(w, 0) == 2) + goto out; + wwprintf(w, "(0x%x)\t\"%s\"\n", s->s_data, s->s_data); + } + waitnl(w); +out: + closeiwin(w); +#else + error("No string debugging."); +#endif +} diff --git a/window/cmd7.c b/window/cmd7.c new file mode 100644 index 0000000..5d17623 --- /dev/null +++ b/window/cmd7.c @@ -0,0 +1,294 @@ +/* $NetBSD: cmd7.c,v 1.4 1997/11/21 08:35:54 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)cmd7.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: cmd7.c,v 1.4 1997/11/21 08:35:54 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "defs.h" +#include "window_string.h" + +void unyank __P((void)); +void yank_highlight __P((int, int, int, int)); +void yank_highlight_line __P((int, int, int)); +void yank_line __P((int, int, int)); + +/* + * Window size. + */ +void +c_size(w) + struct ww *w; +{ + int col, row; + + if (!terse) + wwputs("New window size (lower right corner): ", cmdwin); + col = MIN(w->ww_w.r, wwncol) - 1; + row = MIN(w->ww_w.b, wwnrow) - 1; + wwadd(boxwin, framewin->ww_back); + for (;;) { + wwbox(boxwin, w->ww_w.t - 1, w->ww_w.l - 1, + row - w->ww_w.t + 3, col - w->ww_w.l + 3); + wwsetcursor(row, col); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row, &col, w->ww_w.t, w->ww_w.l, + wwnrow - 1, wwncol - 1)) { + case 3: + wwunbox(boxwin); + wwdelete(boxwin); + return; + case 2: + wwunbox(boxwin); + break; + case 1: + wwunbox(boxwin); + case 0: + continue; + } + break; + } + wwdelete(boxwin); + if (!terse) + wwputc('\n', cmdwin); + wwcurtowin(cmdwin); + sizewin(w, row - w->ww_w.t + 1, col - w->ww_w.l + 1); +} + +/* + * Yank and put + */ + +struct yb { + char *line; + int length; + struct yb *link; +}; +struct yb *yb_head, *yb_tail; + +void +c_yank() +{ + struct ww *w = selwin; + int col1, row1; + int col2, row2; + int r, c; + + if (!terse) + wwputs("Yank starting position: ", cmdwin); + wwcursor(w, 0); + row1 = w->ww_cur.r; + col1 = w->ww_cur.c; + for (;;) { + wwsetcursor(row1, col1); + while (wwpeekc() < 0) + wwiomux(); + switch (getpos(&row1, &col1, w->ww_i.t, w->ww_i.l, + w->ww_i.b - 1, w->ww_i.r - 1)) { + case 3: + goto out; + case 2: + break; + case 1: + case 0: + continue; + } + break; + } + if (!terse) + wwputs("\nYank ending position: ", cmdwin); + row2 = row1; + col2 = col1; + for (;;) { + wwsetcursor(row2, col2); + while (wwpeekc() < 0) + wwiomux(); + r = row2; + c = col2; + switch (getpos(&row2, &col2, w->ww_i.t, w->ww_i.l, + w->ww_i.b - 1, w->ww_i.r - 1)) { + case 3: + yank_highlight(row1, col1, r, c); + goto out; + case 2: + break; + case 1: + yank_highlight(row1, col1, r, c); + yank_highlight(row1, col1, row2, col2); + case 0: + continue; + } + break; + } + if (row2 < row1 || (row2 == row1 && col2 < col1)) { + r = row1; + c = col1; + row1 = row2; + col1 = col2; + row2 = r; + col2 = c; + } + unyank(); + c = col1; + for (r = row1; r < row2; r++) { + yank_line(r, c, w->ww_b.r); + c = w->ww_b.l; + } + yank_line(r, c, col2); + yank_highlight(row1, col1, row2, col2); + if (!terse) + wwputc('\n', cmdwin); +out: + wwcursor(w, 1); +} + +void +yank_highlight(row1, col1, row2, col2) + int row1, col1, row2, col2; +{ + struct ww *w = selwin; + int r, c; + + if ((wwavailmodes & WWM_REV) == 0) + return; + if (row2 < row1 || (row2 == row1 && col2 < col1)) { + r = row1; + c = col1; + row1 = row2; + col1 = col2; + row2 = r; + col2 = c; + } + c = col1; + for (r = row1; r < row2; r++) { + yank_highlight_line(r, c, w->ww_b.r); + c = w->ww_b.l; + } + yank_highlight_line(r, c, col2); +} + +void +yank_highlight_line(r, c, cend) + int r, c, cend; +{ + struct ww *w = selwin; + char *win; + + if (r < w->ww_i.t || r >= w->ww_i.b) + return; + if (c < w->ww_i.l) + c = w->ww_i.l; + if (cend >= w->ww_i.r) + cend = w->ww_i.r; + for (win = w->ww_win[r] + c; c < cend; c++, win++) { + *win ^= WWM_REV; + if (wwsmap[r][c] == w->ww_index) { + if (*win == 0) + w->ww_nvis[r]++; + else if (*win == WWM_REV) + w->ww_nvis[r]--; + wwns[r][c].c_m ^= WWM_REV; + wwtouched[r] |= WWU_TOUCHED; + } + } +} + +void +unyank() +{ + struct yb *yp, *yq; + + for (yp = yb_head; yp; yp = yq) { + yq = yp->link; + str_free(yp->line); + free((char *) yp); + } + yb_head = yb_tail = 0; +} + +void +yank_line(r, c, cend) + int r, c, cend; +{ + struct yb *yp; + int nl = 0; + int n; + union ww_char *bp; + char *cp; + + if (c == cend) + return; + if ((yp = (struct yb *) malloc(sizeof *yp)) == 0) + return; + yp->link = 0; + nl = cend == selwin->ww_b.r; + bp = selwin->ww_buf[r]; + for (cend--; cend >= c; cend--) + if (bp[cend].c_c != ' ') + break; + yp->length = n = cend - c + 1; + if (nl) + yp->length++; + yp->line = str_alloc(yp->length + 1); + for (bp += c, cp = yp->line; --n >= 0;) + *cp++ = bp++->c_c; + if (nl) + *cp++ = '\n'; + *cp = 0; + if (yb_head) + yb_tail = yb_tail->link = yp; + else + yb_head = yb_tail = yp; +} + +void +c_put() +{ + struct yb *yp; + + for (yp = yb_head; yp; yp = yp->link) + (void) write(selwin->ww_pty, yp->line, yp->length); +} diff --git a/window/compress.c b/window/compress.c new file mode 100644 index 0000000..edc233e --- /dev/null +++ b/window/compress.c @@ -0,0 +1,940 @@ +/* $NetBSD: compress.c,v 1.4 1997/11/21 08:35:56 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)compress.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: compress.c,v 1.4 1997/11/21 08:35:56 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include "defs.h" +#include "tt.h" + + /* special */ +int cc_trace = 0; +FILE *cc_trace_fp; + + /* tunable parameters */ + +int cc_reverse = 1; +int cc_sort = 0; +int cc_chop = 0; + +int cc_token_max = 8; /* <= TOKEN_MAX */ +int cc_token_min = 2; /* > tt.tt_put_token_cost */ +int cc_npass0 = 1; +int cc_npass1 = 1; + +int cc_bufsize = 1024 * 3; /* XXX, or 80 * 24 * 2 */ + +int cc_ntoken = 8192; + +#define cc_weight XXX +#ifndef cc_weight +int cc_weight = 0; +#endif + +#define TOKEN_MAX 16 + +struct cc { + char string[TOKEN_MAX]; + char length; + char flag; +#ifndef cc_weight + short weight; +#endif + long time; /* time last seen */ + short bcount; /* count in this buffer */ + short ccount; /* count in compression */ + short places; /* places in the buffer */ + short code; /* token code */ + struct cc *qforw, *qback; + struct cc *hforw, **hback; +}; + +short cc_thresholds[TOKEN_MAX + 1]; +#define thresh(length) (cc_thresholds[length]) +#define threshp(code, count, length) \ + ((code) >= 0 || (short) (count) >= cc_thresholds[length]) + +#ifndef cc_weight +short cc_wthresholds[TOKEN_MAX + 1]; +#define wthresh(length) (cc_wthresholds[length]) +#define wthreshp(weight, length) ((short) (weight) >= cc_wthresholds[length]) +#else +#define wthreshp(weight, length) (0) +#endif + +#ifndef cc_weight +short cc_wlimits[TOKEN_MAX + 1]; +#define wlimit(length) (cc_wlimits[length]) +#endif + +#define put_token_score(length) ((length) - tt.tt_put_token_cost) + +int cc_score_adjustments[TOKEN_MAX + 1][8]; /* XXX, 8 > max of cc_thresholds */ +#define score_adjust(score, p) \ + do { \ + int length = (p)->length; \ + int ccount = (p)->ccount; \ + if (threshp((p)->code, ccount, length) || \ + wthreshp((p)->weight, length)) /* XXX */ \ + (score) -= length - tt.tt_put_token_cost; \ + else \ + (score) += cc_score_adjustments[length][ccount]; \ + } while (0) + +int cc_initial_scores[TOKEN_MAX + 1][8]; /* XXX, 8 > max of cc_thresholds */ + +struct cc cc_q0a, cc_q0b, cc_q1a, cc_q1b; + +#define qinsert(p1, p2) \ + do { \ + struct cc *forw = (p1)->qforw; \ + struct cc *back = (p1)->qback; \ + back->qforw = forw; \ + forw->qback = back; \ + forw = (p2)->qforw; \ + (p1)->qforw = forw; \ + forw->qback = (p1); \ + (p2)->qforw = (p1); \ + (p1)->qback = (p2); \ + } while (0) + +#define qinsertq(q, p) \ + ((q)->qforw == (q) ? 0 : \ + ((q)->qback->qforw = (p)->qforw, \ + (p)->qforw->qback = (q)->qback, \ + (q)->qforw->qback = (p), \ + (p)->qforw = (q)->qforw, \ + (q)->qforw = (q), \ + (q)->qback = (q))) + +#define H (14) +#define HSIZE (1 << H) +#define hash(h, c) (((((h) >> (H - 8)) | (h) << 8) ^ (c)) & (HSIZE - 1)) + +char *cc_buffer; +struct cc **cc_output; /* the output array */ +short *cc_places[TOKEN_MAX + 1]; +short *cc_hashcodes; /* for computing hashcodes */ +struct cc **cc_htab; /* the hash table */ +struct cc **cc_tokens; /* holds all the active tokens */ +struct cc_undo { + struct cc **pos; + struct cc *val; +} *cc_undo; + +long cc_time, cc_time0; + +char *cc_tt_ob, *cc_tt_obe; + +int cc_compress __P((struct cc **, struct cc **, char)); +void cc_compress_cleanup __P((struct cc **, int)); +void cc_compress_phase __P((struct cc **, int, struct cc **, int)); +void cc_compress_phase1 __P((struct cc **, struct cc **, int, int)); +void cc_output_phase __P((char *, struct cc **, int)); +int cc_sweep __P((char *, int, struct cc **, int)); +void cc_sweep0 __P((char *, int, int)); +int cc_sweep_phase __P((char *, int, struct cc **)); +void cc_sweep_reverse __P((struct cc **, short *)); +int cc_token_compare __P((const void *, const void *)); + +int +ccinit() +{ + int i, j; + struct cc *p; + + if (tt.tt_token_max > cc_token_max) + tt.tt_token_max = cc_token_max; + if (tt.tt_token_min < cc_token_min) + tt.tt_token_min = cc_token_min; + if (tt.tt_token_min > tt.tt_token_max) { + tt.tt_ntoken = 0; + return 0; + } + if (tt.tt_ntoken > cc_ntoken / 2) /* not likely */ + tt.tt_ntoken = cc_ntoken / 2; +#define C(x) (sizeof (x) / sizeof *(x)) + for (i = 0; i < C(cc_thresholds); i++) { + int h = i - tt.tt_put_token_cost; + if (h > 0) + cc_thresholds[i] = + (tt.tt_set_token_cost + 1 + h - 1) / h + 1; + else + cc_thresholds[i] = 0; + } + for (i = 0; i < C(cc_score_adjustments); i++) { + int t = cc_thresholds[i]; + for (j = 0; j < C(*cc_score_adjustments); j++) { + if (j >= t) + cc_score_adjustments[i][j] = + - (i - tt.tt_put_token_cost); + else if (j < t - 1) + cc_score_adjustments[i][j] = 0; + else + /* + * cost now is + * length * (ccount + 1) a + * cost before was + * set-token-cost + length + + * ccount * put-token-cost b + * the score adjustment is (b - a) + */ + cc_score_adjustments[i][j] = + tt.tt_set_token_cost + i + + j * tt.tt_put_token_cost - + i * (j + 1); + if (j >= t) + cc_initial_scores[i][j] = 0; + else + /* + * - (set-token-cost + + * (length - put-token-cost) - + * (length - put-token-cost) * ccount) + */ + cc_initial_scores[i][j] = + - (tt.tt_set_token_cost + + (i - tt.tt_put_token_cost) - + (i - tt.tt_put_token_cost) * j); + } + } +#ifndef cc_weight + for (i = 1; i < C(cc_wthresholds); i++) { + cc_wthresholds[i] = + ((tt.tt_set_token_cost + tt.tt_put_token_cost) / i + + i / 5 + 1) * + cc_weight + 1; + cc_wlimits[i] = cc_wthresholds[i] + cc_weight; + } +#endif +#undef C + if ((cc_output = (struct cc **) + malloc((unsigned) cc_bufsize * sizeof *cc_output)) == 0) + goto nomem; + if ((cc_hashcodes = (short *) + malloc((unsigned) cc_bufsize * sizeof *cc_hashcodes)) == 0) + goto nomem; + if ((cc_htab = (struct cc **) malloc(HSIZE * sizeof *cc_htab)) == 0) + goto nomem; + if ((cc_tokens = (struct cc **) + malloc((unsigned) + (cc_ntoken + tt.tt_token_max - tt.tt_token_min + 1) * + sizeof *cc_tokens)) == 0) + goto nomem; + if ((cc_undo = (struct cc_undo *) + malloc((unsigned) cc_bufsize * sizeof *cc_undo)) == 0) + goto nomem; + for (i = tt.tt_token_min; i <= tt.tt_token_max; i++) + if ((cc_places[i] = (short *) + malloc((unsigned) cc_bufsize * sizeof **cc_places)) == 0) + goto nomem; + cc_q0a.qforw = cc_q0a.qback = &cc_q0a; + cc_q0b.qforw = cc_q0b.qback = &cc_q0b; + cc_q1a.qforw = cc_q1a.qback = &cc_q1a; + cc_q1b.qforw = cc_q1b.qback = &cc_q1b; + if ((p = (struct cc *) malloc((unsigned) cc_ntoken * sizeof *p)) == 0) + goto nomem; + for (i = 0; i < tt.tt_ntoken; i++) { + p->code = i; + p->time = -1; + p->qback = cc_q0a.qback; + p->qforw = &cc_q0a; + p->qback->qforw = p; + cc_q0a.qback = p; + p++; + } + for (; i < cc_ntoken; i++) { + p->code = -1; + p->time = -1; + p->qback = cc_q1a.qback; + p->qforw = &cc_q1a; + p->qback->qforw = p; + cc_q1a.qback = p; + p++; + } + cc_tt_ob = tt_ob; + cc_tt_obe = tt_obe; + if ((cc_buffer = malloc((unsigned) cc_bufsize)) == 0) + goto nomem; + return 0; +nomem: + wwerrno = WWE_NOMEM; + return -1; +} + +void +ccstart() +{ + ttflush(); + tt_obp = tt_ob = cc_buffer; + tt_obe = tt_ob + cc_bufsize; + tt.tt_flush = ccflush; + if (cc_trace) { + cc_trace_fp = fopen("window-trace", "a"); + (void) fcntl(fileno(cc_trace_fp), F_SETFD, 1); + } + ccreset(); +} + +void +ccreset() +{ + struct cc *p; + + memset((char *) cc_htab, 0, HSIZE * sizeof *cc_htab); + for (p = cc_q0a.qforw; p != &cc_q0a; p = p->qforw) + p->hback = 0; + for (p = cc_q1a.qforw; p != &cc_q1a; p = p->qforw) + p->hback = 0; +} + +void +ccend() +{ + + ttflush(); + tt_obp = tt_ob = cc_tt_ob; + tt_obe = cc_tt_obe; + tt.tt_flush = 0; + if (cc_trace_fp != NULL) { + (void) fclose(cc_trace_fp); + cc_trace_fp = NULL; + } +} + +void +ccflush() +{ + int bufsize = tt_obp - tt_ob; + int n; + + if (tt_ob != cc_buffer) + abort(); + if (cc_trace_fp != NULL) { + (void) fwrite(tt_ob, 1, bufsize, cc_trace_fp); + (void) putc(-1, cc_trace_fp); + } + tt.tt_flush = 0; + (*tt.tt_compress)(1); + if (bufsize < tt.tt_token_min) { + ttflush(); + goto out; + } + tt_obp = tt_ob = cc_tt_ob; + tt_obe = cc_tt_obe; + cc_time0 = cc_time; + cc_time += bufsize; + n = cc_sweep_phase(cc_buffer, bufsize, cc_tokens); + cc_compress_phase(cc_output, bufsize, cc_tokens, n); + cc_output_phase(cc_buffer, cc_output, bufsize); + ttflush(); + tt_obp = tt_ob = cc_buffer; + tt_obe = cc_buffer + cc_bufsize; +out: + (*tt.tt_compress)(0); + tt.tt_flush = ccflush; +} + +int +cc_sweep_phase(buffer, bufsize, tokens) + char *buffer; + int bufsize; + struct cc **tokens; +{ + struct cc **pp = tokens; + int i, n; +#ifdef STATS + int nn, ii; +#endif + +#ifdef STATS + if (verbose >= 0) + time_begin(); + if (verbose > 0) + printf("Sweep:"); +#endif + cc_sweep0(buffer, bufsize, tt.tt_token_min - 1); +#ifdef STATS + ntoken_stat = 0; + nn = 0; + ii = 0; +#endif + for (i = tt.tt_token_min; i <= tt.tt_token_max; i++) { +#ifdef STATS + if (verbose > 0) { + if (ii > 7) { + printf("\n "); + ii = 0; + } + ii++; + printf(" (%d", i); + (void) fflush(stdout); + } +#endif + n = cc_sweep(buffer, bufsize, pp, i); + pp += n; +#ifdef STATS + if (verbose > 0) { + if (--n > 0) { + printf(" %d", n); + nn += n; + } + putchar(')'); + } +#endif + } + qinsertq(&cc_q1b, &cc_q1a); +#ifdef STATS + if (verbose > 0) + printf("\n %d tokens, %d candidates\n", + ntoken_stat, nn); + if (verbose >= 0) + time_end(); +#endif + return pp - tokens; +} + +void +cc_sweep0(buffer, n, length) + char *buffer; + int n, length; +{ + char *p; + short *hc; + int i; + short c; + short pc = tt.tt_padc; + + /* n and length are at least 1 */ + p = buffer++; + hc = cc_hashcodes; + i = n; + do { + if ((*hc++ = *p++) == pc) + hc[-1] = -1; + } while (--i); + while (--length) { + p = buffer++; + hc = cc_hashcodes; + for (i = n--; --i;) { + if ((c = *p++) == pc || *hc < 0) + c = -1; + else + c = hash(*hc, c); + *hc++ = c; + } + } +} + +int +cc_sweep(buffer, bufsize, tokens, length) + char *buffer; + int bufsize; + struct cc **tokens; + int length; +{ + struct cc *p; + char *cp; + int i; + short *hc; + short *places = cc_places[length]; + struct cc **pp = tokens; + short threshold = thresh(length); +#ifndef cc_weight + short wthreshold = wthresh(length); + short limit = wlimit(length); +#endif + int time; + short pc = tt.tt_padc; + + i = length - 1; + bufsize -= i; + cp = buffer + i; + hc = cc_hashcodes; + time = cc_time0; + for (i = 0; i < bufsize; i++, time++) { + struct cc **h; + + { + short *hc1 = hc; + short c = *cp++; + short hh; + if ((hh = *hc1) < 0 || c == pc) { + *hc1++ = -1; + hc = hc1; + continue; + } + h = cc_htab + (*hc1++ = hash(hh, c)); + hc = hc1; + } + for (p = *h; p != 0; p = p->hforw) + if (p->length == (char) length) { + char *p1 = p->string; + char *p2 = cp - length; + int n = length; + do + if (*p1++ != *p2++) + goto fail; + while (--n); + break; + fail:; + } + if (p == 0) { + p = cc_q1a.qback; + if (p == &cc_q1a || + (p->time >= cc_time0 && p->length == (char) length)) + continue; + if (p->hback != 0) + if ((*p->hback = p->hforw) != 0) + p->hforw->hback = p->hback; + { + char *p1 = p->string; + char *p2 = cp - length; + int n = length; + do + *p1++ = *p2++; + while (--n); + } + p->length = length; +#ifndef cc_weight + p->weight = cc_weight; +#endif + p->time = time; + p->bcount = 1; + p->ccount = 0; + p->flag = 0; + if ((p->hforw = *h) != 0) + p->hforw->hback = &p->hforw; + *h = p; + p->hback = h; + qinsert(p, &cc_q1a); + places[i] = -1; + p->places = i; +#ifdef STATS + ntoken_stat++; +#endif + } else if (p->time < cc_time0) { +#ifndef cc_weight + if ((p->weight += p->time - time) < 0) + p->weight = cc_weight; + else if ((p->weight += cc_weight) > limit) + p->weight = limit; +#endif + p->time = time; + p->bcount = 1; + p->ccount = 0; + if (p->code >= 0) { + p->flag = 1; + *pp++ = p; + } else +#ifndef cc_weight + if (p->weight >= wthreshold) { + p->flag = 1; + *pp++ = p; + qinsert(p, &cc_q1b); + } else +#endif + { + p->flag = 0; + qinsert(p, &cc_q1a); + } + places[i] = -1; + p->places = i; +#ifdef STATS + ntoken_stat++; +#endif + } else if (p->time + length > time) { + /* + * overlapping token, don't count as two and + * don't update time, but do adjust weight to offset + * the difference + */ +#ifndef cc_weight + if (cc_weight != 0) { /* XXX */ + p->weight += time - p->time; + if (!p->flag && p->weight >= wthreshold) { + p->flag = 1; + *pp++ = p; + qinsert(p, &cc_q1b); + } + } +#endif + places[i] = p->places; + p->places = i; + } else { +#ifndef cc_weight + if ((p->weight += p->time - time) < 0) + p->weight = cc_weight; + else if ((p->weight += cc_weight) > limit) + p->weight = limit; +#endif + p->time = time; + p->bcount++; + if (!p->flag && + /* code must be < 0 if flag false here */ + (p->bcount >= threshold +#ifndef cc_weight + || p->weight >= wthreshold +#endif + )) { + p->flag = 1; + *pp++ = p; + qinsert(p, &cc_q1b); + } + places[i] = p->places; + p->places = i; + } + } + if ((i = pp - tokens) > 0) { + *pp = 0; + if (cc_reverse) + cc_sweep_reverse(tokens, places); + if (cc_sort && i > 1) { + qsort((char *) tokens, i, sizeof *tokens, + cc_token_compare); + } + if (cc_chop) { + if ((i = i * cc_chop / 100) == 0) + i = 1; + tokens[i] = 0; + } + i++; + } + return i; +} + +void +cc_sweep_reverse(pp, places) + struct cc **pp; + short *places; +{ + struct cc *p; + short front, back, t; + + while ((p = *pp++) != 0) { + back = -1; + t = p->places; + /* the list is never empty */ + do { + front = places[t]; + places[t] = back; + back = t; + } while ((t = front) >= 0); + p->places = back; + } +} + +void +cc_compress_phase(output, bufsize, tokens, ntoken) + struct cc **output; + int bufsize; + struct cc **tokens; + int ntoken; +{ + int i; + + memset((char *) output, 0, bufsize * sizeof *output); + for (i = 0; i < cc_npass0; i++) + cc_compress_phase1(output, tokens, ntoken, 0); + for (i = 0; i < cc_npass1; i++) + cc_compress_phase1(output, tokens, ntoken, 1); + cc_compress_cleanup(output, bufsize); +} + +void +cc_compress_phase1(output, tokens, ntoken, flag) + struct cc **output; + struct cc **tokens; + int ntoken, flag; +{ + struct cc **pp; +#ifdef STATS + int i = 0; + int nt = 0, cc = 0, nc = 0; +#endif + +#ifdef STATS + if (verbose >= 0) + time_begin(); + if (verbose > 0) + printf("Compress:"); +#endif + pp = tokens; + while (pp < tokens + ntoken) { +#ifdef STATS + if (verbose > 0) { + ntoken_stat = 0; + ccount_stat = 0; + ncover_stat = 0; + if (i > 2) { + printf("\n "); + i = 0; + } + i++; + printf(" (%d", (*pp)->length); + (void) fflush(stdout); + } +#endif + pp += cc_compress(output, pp, flag); +#ifdef STATS + if (verbose > 0) { + printf(" %dt %du %dc)", ntoken_stat, ccount_stat, + ncover_stat); + nt += ntoken_stat; + cc += ccount_stat; + nc += ncover_stat; + } +#endif + } +#ifdef STATS + if (verbose > 0) + printf("\n total: (%dt %du %dc)\n", nt, cc, nc); + if (verbose >= 0) + time_end(); +#endif +} + +void +cc_compress_cleanup(output, bufsize) + struct cc **output; + int bufsize; +{ + struct cc **end; + + /* the previous output phase may have been interrupted */ + qinsertq(&cc_q0b, &cc_q0a); + for (end = output + bufsize; output < end;) { + struct cc *p; + int length; + if ((p = *output) == 0) { + output++; + continue; + } + length = p->length; + if (!p->flag) { + } else if (p->code >= 0) { + qinsert(p, &cc_q0b); + p->flag = 0; + } else if (p->ccount == 0) { + *output = 0; + } else if (p->ccount >= thresh(length) +#ifndef cc_weight + || wthreshp(p->weight, length) +#endif + ) { + p->flag = 0; + } else { + p->ccount = 0; + *output = 0; + } + output += length; + } +} + +int +cc_compress(output, tokens, flag) + struct cc **output; + struct cc **tokens; + char flag; +{ + struct cc **pp = tokens; + struct cc *p = *pp++; + int length = p->length; + int threshold = thresh(length); +#ifndef cc_weight + short wthreshold = wthresh(length); +#endif + short *places = cc_places[length]; + int *initial_scores = cc_initial_scores[length]; + int initial_score0 = put_token_score(length); + + do { + int score; + struct cc_undo *undop; + int ccount; +#ifdef STATS + int ncover; +#endif + int i; + + ccount = p->ccount; + if ((short) ccount >= p->bcount) + continue; + if (p->code >= 0 || ccount >= threshold) + score = 0; +#ifndef cc_weight + else if (p->weight >= wthreshold) + /* allow one fewer match than normal */ + /* XXX, should adjust for ccount */ + score = - tt.tt_set_token_cost; +#endif + else + score = initial_scores[ccount]; + undop = cc_undo; +#ifdef STATS + ncover = 0; +#endif + for (i = p->places; i >= 0; i = places[i]) { + struct cc **jp; + struct cc *x; + struct cc **ip = output + i; + int score0 = initial_score0; + struct cc **iip = ip + length; + struct cc_undo *undop1 = undop; + + if ((x = *(jp = ip)) != 0) + goto z; + while (--jp >= output) + if ((x = *jp) != 0) { + if (jp + x->length > ip) + goto z; + break; + } + jp = ip + 1; + while (jp < iip) { + if ((x = *jp) == 0) { + jp++; + continue; + } + z: + if (x == p) + goto undo; +#ifdef STATS + ncover++; +#endif + undop->pos = jp; + undop->val = x; + undop++; + *jp = 0; + x->ccount--; + score_adjust(score0, x); + if (score0 < 0 && flag) + goto undo; + jp += x->length; + } + undop->pos = ip; + undop->val = 0; + undop++; + *ip = p; + ccount++; + score += score0; + continue; + undo: + while (--undop >= undop1) + if ((*undop->pos = x = undop->val)) + x->ccount++; + undop++; + } + if (score > 0) { +#ifdef STATS + ccount_stat += ccount - p->ccount; + ntoken_stat++; + ncover_stat += ncover; +#endif + p->ccount = ccount; + } else { + struct cc_undo *u = cc_undo; + while (--undop >= u) { + struct cc *x; + if ((*undop->pos = x = undop->val)) + x->ccount++; + } + } + } while ((p = *pp++) != 0); + return pp - tokens; +} + +void +cc_output_phase(buffer, output, bufsize) + char *buffer; + struct cc **output; + int bufsize; +{ + int i; + struct cc *p, *p1; + + for (i = 0; i < bufsize;) { + if ((p = output[i]) == 0) { + ttputc(buffer[i]); + i++; + } else if (p->code >= 0) { + if (--p->ccount == 0) + qinsert(p, &cc_q0a); + (*tt.tt_put_token)(p->code, p->string, p->length); + wwntokuse++; + wwntoksave += put_token_score(p->length); + i += p->length; + } else if ((p1 = cc_q0a.qback) != &cc_q0a) { + p->code = p1->code; + p1->code = -1; + qinsert(p1, &cc_q1a); + if (--p->ccount == 0) + qinsert(p, &cc_q0a); + else + qinsert(p, &cc_q0b); + (*tt.tt_set_token)(p->code, p->string, p->length); + wwntokdef++; + wwntoksave -= tt.tt_set_token_cost; + i += p->length; + } else { + p->ccount--; + ttwrite(p->string, p->length); + wwntokbad++; + i += p->length; + } + } + wwntokc += bufsize; +} + +int +cc_token_compare(p1, p2) + const void *p1, *p2; +{ + const struct cc **vp1 = (void *)p1; + const struct cc **vp2 = (void *)p2; + return (*vp2)->bcount - (*vp1)->bcount; +} diff --git a/window/context.c b/window/context.c new file mode 100644 index 0000000..4409a69 --- /dev/null +++ b/window/context.c @@ -0,0 +1,147 @@ +/* $NetBSD: context.c,v 1.4 1997/11/21 08:35:58 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)context.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: context.c,v 1.4 1997/11/21 08:35:58 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "defs.h" +#include "window_string.h" +#undef EXTERN +#define EXTERN +#include "context.h" +#undef EXTERN + +/* + * Context push/pop for nested command files. + */ +int cx_alloc __P((void)); +void cx_free __P((void)); + +int +cx_alloc() +{ + struct context *xp; + + if (cx.x_type != 0) { + xp = (struct context *) + malloc((unsigned) sizeof (struct context)); + if (xp == 0) + return -1; + *xp = cx; + cx.x_link = xp; + cx.x_type = 0; + } + cx.x_erred = 0; + cx.x_synerred = 0; + cx.x_abort = 0; + return 0; +} + +void +cx_free() +{ + struct context *xp; + + if ((xp = cx.x_link) != 0) { + cx = *xp; + free((char *)xp); + } else + cx.x_type = 0; +} + +int +cx_beginfile(filename) + char *filename; +{ + if (cx_alloc() < 0) + return -1; + cx.x_type = X_FILE; + if ((cx.x_filename = str_cpy(filename)) == 0) + goto bad; + cx.x_fp = fopen(filename, "r"); + if (cx.x_fp == 0) + goto bad; + (void) fcntl(fileno(cx.x_fp), F_SETFD, 1); + cx.x_bol = 1; + cx.x_lineno = 0; + cx.x_errwin = 0; + cx.x_noerr = 0; + return 0; +bad: + if (cx.x_filename != 0) + str_free(cx.x_filename); + cx_free(); + return -1; +} + +int +cx_beginbuf(buf, arg, narg) + char *buf; + struct value *arg; + int narg; +{ + if (cx_alloc() < 0) + return -1; + cx.x_type = X_BUF; + cx.x_bufp = cx.x_buf = buf; + cx.x_arg = arg; + cx.x_narg = narg; + return 0; +} + +void +cx_end() +{ + switch (cx.x_type) { + case X_BUF: + break; + case X_FILE: + (void) fclose(cx.x_fp); + str_free(cx.x_filename); + break; + } + cx_free(); +} diff --git a/window/context.h b/window/context.h new file mode 100644 index 0000000..0f9b5a0 --- /dev/null +++ b/window/context.h @@ -0,0 +1,89 @@ +/* $NetBSD: context.h,v 1.3 1995/09/28 10:34:17 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)context.h 8.1 (Berkeley) 6/6/93 + */ + +#include + +#ifndef EXTERN +#define EXTERN extern +#endif + +struct context { + struct context *x_link; /* nested contexts */ + char x_type; /* tag for union */ + union { + struct { /* input is a file */ + char *X_filename; /* input file name */ + FILE *X_fp; /* input stream */ + short X_lineno; /* current line number */ + char X_bol; /* at beginning of line */ + char X_noerr; /* don't report errors */ + struct ww *X_errwin; /* error window */ + } x_f; + struct { /* input is a buffer */ + char *X_buf; /* input buffer */ + char *X_bufp; /* current position in buf */ + struct value *X_arg; /* argument for alias */ + int X_narg; /* number of arguments */ + } x_b; + } x_un; + /* holding place for current token */ + int x_token; /* the token */ + struct value x_val; /* values associated with token */ + /* parser error flags */ + unsigned x_erred :1; /* had an error */ + unsigned x_synerred :1; /* had syntax error */ + unsigned x_abort :1; /* fatal error */ +}; +#define x_buf x_un.x_b.X_buf +#define x_bufp x_un.x_b.X_bufp +#define x_arg x_un.x_b.X_arg +#define x_narg x_un.x_b.X_narg +#define x_filename x_un.x_f.X_filename +#define x_fp x_un.x_f.X_fp +#define x_lineno x_un.x_f.X_lineno +#define x_bol x_un.x_f.X_bol +#define x_errwin x_un.x_f.X_errwin +#define x_noerr x_un.x_f.X_noerr + + /* x_type values, 0 is reserved */ +#define X_FILE 1 /* input is a file */ +#define X_BUF 2 /* input is a buffer */ + +EXTERN struct context cx; /* the current context */ diff --git a/window/defs.h b/window/defs.h new file mode 100644 index 0000000..f1bbb68 --- /dev/null +++ b/window/defs.h @@ -0,0 +1,131 @@ +/* $NetBSD: defs.h,v 1.4 1997/11/21 08:35:59 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)defs.h 8.1 (Berkeley) 6/6/93 + */ + +#include +#include "value.h" +#include "ww.h" + +#ifndef EXTERN +#define EXTERN extern +#endif + +#define NWINDOW 9 + +EXTERN struct timeval starttime; + +EXTERN struct ww *window[NWINDOW]; /* the windows */ +EXTERN struct ww *selwin; /* the selected window */ +EXTERN struct ww *lastselwin; /* the last selected window */ +EXTERN struct ww *cmdwin; /* the command window */ +EXTERN struct ww *framewin; /* the window for framing */ +EXTERN struct ww *boxwin; /* the window for the box */ +EXTERN struct ww *fgwin; /* the last foreground window */ + +#define isfg(w) ((w)->ww_order <= fgwin->ww_order) + +EXTERN char *default_shell[128]; /* default shell argv */ +EXTERN char *default_shellfile; /* default shell program */ +EXTERN int default_nline; /* default buffer size for new windows */ +EXTERN int default_smooth; /* default "smooth" parameter */ +EXTERN char escapec; /* the escape character */ + +/* flags */ +EXTERN char quit; /* quit command issued */ +EXTERN char terse; /* terse mode */ +EXTERN char debug; /* debug mode */ +EXTERN char incmd; /* in command mode */ + +void addwin __P((struct ww *, char)); +int ccinit __P((void)); +void ccend __P((void)); +void ccflush __P((void)); +void ccreset __P((void)); +void ccstart __P((void)); +void c_colon __P((void)); +void c_debug __P((void)); +void c_help __P((void)); +void c_move __P((struct ww *)); +void c_put __P((void)); +void c_quit __P((void)); +void c_size __P((struct ww *)); +void c_window __P((void)); +void c_yank __P((void)); +void closeiwin __P((struct ww *)); +void closewin __P((struct ww *)); +void closewin1 __P((struct ww *)); +int cx_beginbuf __P((char *, struct value *, int)); +int cx_beginfile __P((char *)); +void cx_end __P((void)); +void deletewin __P((struct ww *)); +void docmd __P((void)); +int doconfig __P((void)); +void dodefault __P((void)); +int dolongcmd __P((char *, struct value *, int)); +int dosource __P((char *)); +void error __P((const char *, ...)); +void err_end __P((void)); +int findid __P((void)); +struct ww *findselwin __P((void)); +void front __P((struct ww *, char)); +int getpos __P((int *, int *, int, int, int, int)); +struct ww *getwin __P((void)); +void labelwin __P((struct ww *)); +void mloop __P((void)); +int more __P((struct ww *, char)); +void movewin __P((struct ww *, int, int)); +struct ww *openwin __P((int, int, int, int, int, int, char *, int, int, + char *, char **)); +struct ww *openiwin __P((int, char *)); +void p_memerror __P((void)); +void p_start __P((void)); +void reframe __P((void)); +void setcmd __P((char)); +void setescape __P((char *)); +int setlabel __P((struct ww *, char *)); +void setselwin __P((struct ww *)); +void setterse __P((char)); +void setvars __P((void)); +void sizewin __P((struct ww *, int, int)); +void startwin __P((struct ww *)); +void stopwin __P((struct ww *)); +int s_gettok __P((void)); +void verror __P((const char *, va_list)); +void waitnl __P((struct ww *)); +int waitnl1 __P((struct ww *, char *)); diff --git a/window/error.c b/window/error.c new file mode 100644 index 0000000..6c82e23 --- /dev/null +++ b/window/error.c @@ -0,0 +1,123 @@ +/* $NetBSD: error.c,v 1.4 1997/11/21 08:36:00 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)error.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: error.c,v 1.4 1997/11/21 08:36:00 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "context.h" +#include "char.h" + +#define ERRLINES 10 /* number of lines for errwin */ + +void +#if __STDC__ +error(const char *fmt, ...) +#else +error(fmt, va_alist) + char *fmt; + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + verror(fmt, ap); + va_end(ap); +} + +void +verror(fmt, ap) + const char *fmt; + va_list ap; +{ + struct context *x; + struct ww *w; + + for (x = &cx; x != 0 && x->x_type != X_FILE; x = x->x_link) + ; + if (x == 0) { + if (terse) + wwbell(); + else { + wwvprintf(cmdwin, fmt, ap); + wwputs(" ", cmdwin); + } + return; + } + if (x->x_noerr) + return; + if ((w = x->x_errwin) == 0) { + char buf[512]; + + (void) snprintf(buf, sizeof(buf), "Errors from %s", + x->x_filename); + if ((w = x->x_errwin = openiwin(ERRLINES, buf)) == 0) { + wwputs("Can't open error window. ", cmdwin); + x->x_noerr = 1; + return; + } + } + if (more(w, 0) == 2) { + x->x_noerr = 1; + return; + } + wwprintf(w, "line %d: ", x->x_lineno); + wwvprintf(w, fmt, ap); + wwputc('\n', w); +} + +void +err_end() +{ + if (cx.x_type == X_FILE && cx.x_errwin != 0) { + if (!cx.x_noerr) + waitnl(cx.x_errwin); + closeiwin(cx.x_errwin); + cx.x_errwin = 0; + } +} diff --git a/window/lcmd.c b/window/lcmd.c new file mode 100644 index 0000000..cad4116 --- /dev/null +++ b/window/lcmd.c @@ -0,0 +1,139 @@ +/* $NetBSD: lcmd.c,v 1.4 1997/11/21 08:36:01 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)lcmd.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: lcmd.c,v 1.4 1997/11/21 08:36:01 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "lcmd.h" +#include "window_string.h" + +extern struct lcmd_arg arg_alias[]; +extern struct lcmd_arg arg_cursormodes[]; +extern struct lcmd_arg arg_debug[]; +extern struct lcmd_arg arg_echo[]; +extern struct lcmd_arg arg_escape[]; +extern struct lcmd_arg arg_foreground[]; +extern struct lcmd_arg arg_label[]; +extern struct lcmd_arg arg_def_nline[]; +extern struct lcmd_arg arg_def_shell[]; +extern struct lcmd_arg arg_def_smooth[]; +extern struct lcmd_arg arg_close[]; +extern struct lcmd_arg arg_select[]; +extern struct lcmd_arg arg_smooth[]; +extern struct lcmd_arg arg_source[]; +extern struct lcmd_arg arg_terse[]; +extern struct lcmd_arg arg_time[]; +extern struct lcmd_arg arg_unalias[]; +extern struct lcmd_arg arg_unset[]; +extern struct lcmd_arg arg_window[]; +extern struct lcmd_arg arg_write[]; +struct lcmd_arg arg_null[1] = { { 0 } }; + +struct lcmd_tab lcmd_tab[] = { + { "alias", 1, l_alias, arg_alias }, + { "close", 2, l_close, arg_close }, + { "cursormodes", 2, l_cursormodes, arg_cursormodes }, + { "debug", 1, l_debug, arg_debug }, + { "default_nlines", 9, l_def_nline, arg_def_nline }, + { "default_shell", 10, l_def_shell, arg_def_shell }, + { "default_smooth", 10, l_def_smooth, arg_def_smooth }, + { "echo", 2, l_echo, arg_echo }, + { "escape", 2, l_escape, arg_escape }, + { "foreground", 1, l_foreground, arg_foreground }, + { "iostat", 1, l_iostat, arg_null }, + { "label", 2, l_label, arg_label }, + { "list", 2, l_list, arg_null }, + { "nlines", 1, l_def_nline, arg_def_nline }, + { "select", 2, l_select, arg_select }, + { "shell", 2, l_def_shell, arg_def_shell }, + { "smooth", 2, l_smooth, arg_smooth }, + { "source", 2, l_source, arg_source }, + { "terse", 2, l_terse, arg_terse }, + { "time", 2, l_time, arg_time }, + { "unalias", 3, l_unalias, arg_unalias }, + { "unset", 3, l_unset, arg_unset }, + { "variable", 1, l_variable, arg_null }, + { "window", 2, l_window, arg_window }, + { "write", 2, l_write, arg_write }, + { 0, 0, 0, 0 } +}; + +struct lcmd_tab * +lcmd_lookup(name) + char *name; +{ + struct lcmd_tab *p; + + for (p = lcmd_tab; p->lc_name != 0; p++) + if (str_match(name, p->lc_name, p->lc_minlen)) + return p; + return 0; +} + +int +dosource(filename) + char *filename; +{ + if (cx_beginfile(filename) < 0) + return -1; + p_start(); + err_end(); + cx_end(); + return 0; +} + +int +dolongcmd(buffer, arg, narg) + char *buffer; + struct value *arg; + int narg; +{ + if (cx_beginbuf(buffer, arg, narg) < 0) + return -1; + p_start(); + err_end(); + cx_end(); + return 0; +} diff --git a/window/lcmd.h b/window/lcmd.h new file mode 100644 index 0000000..2741a3e --- /dev/null +++ b/window/lcmd.h @@ -0,0 +1,87 @@ +/* $NetBSD: lcmd.h,v 1.4 1997/11/21 08:36:02 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)lcmd.h 8.1 (Berkeley) 6/6/93 + */ + +#define LCMD_NARG 20 /* maximum number of arguments */ + +struct lcmd_tab { + char *lc_name; + int lc_minlen; + void (*lc_func) __P((struct value *, struct value *)); + struct lcmd_arg *lc_arg; +}; + +struct lcmd_arg { + char *arg_name; + int arg_minlen; + int arg_flags; +}; + + /* arg_flags bits */ +#define ARG_TYPE 0x0f /* type of arg */ +#define ARG_ANY 0x00 /* any type */ +#define ARG_NUM 0x01 /* must be a number */ +#define ARG_STR 0x02 /* must be a string */ +#define ARG_LIST 0x10 /* this arg can be a list */ + +struct lcmd_tab *lcmd_lookup __P((char *)); +void l_alias __P((struct value *, struct value *)); +void l_close __P((struct value *, struct value *)); +void l_cursormodes __P((struct value *, struct value *)); +void l_debug __P((struct value *, struct value *)); +void l_def_nline __P((struct value *, struct value *)); +void l_def_shell __P((struct value *, struct value *)); +void l_def_smooth __P((struct value *, struct value *)); +void l_echo __P((struct value *, struct value *)); +void l_escape __P((struct value *, struct value *)); +void l_foreground __P((struct value *, struct value *)); +void l_iostat __P((struct value *, struct value *)); +void l_label __P((struct value *, struct value *)); +void l_list __P((struct value *, struct value *)); +void l_select __P((struct value *, struct value *)); +void l_smooth __P((struct value *, struct value *)); +void l_source __P((struct value *, struct value *)); +void l_terse __P((struct value *, struct value *)); +void l_time __P((struct value *, struct value *)); +void l_unalias __P((struct value *, struct value *)); +void l_unset __P((struct value *, struct value *)); +void l_variable __P((struct value *, struct value *)); +void l_window __P((struct value *, struct value *)); +void l_write __P((struct value *, struct value *)); +struct ww *vtowin __P((struct value *, struct ww *)); diff --git a/window/lcmd1.c b/window/lcmd1.c new file mode 100644 index 0000000..a856d3d --- /dev/null +++ b/window/lcmd1.c @@ -0,0 +1,466 @@ +/* $NetBSD: lcmd1.c,v 1.7 1997/11/21 08:36:03 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)lcmd1.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: lcmd1.c,v 1.7 1997/11/21 08:36:03 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "defs.h" +#include "window_string.h" +#include "lcmd.h" +#include "var.h" + +char vtobool __P((struct value *, char, char)); + +struct lcmd_arg arg_window[] = { + { "row", 1, ARG_NUM }, + { "column", 1, ARG_NUM }, + { "nrows", 2, ARG_NUM }, + { "ncols", 2, ARG_NUM }, + { "nlines", 2, ARG_NUM }, + { "label", 1, ARG_STR }, + { "pty", 1, ARG_ANY }, + { "frame", 1, ARG_ANY }, + { "mapnl", 1, ARG_ANY }, + { "keepopen", 1, ARG_ANY }, + { "smooth", 1, ARG_ANY }, + { "shell", 1, ARG_STR|ARG_LIST }, + { 0 } +}; + +void +l_window(v, a) + struct value *v; + struct value *a; +{ + struct ww *w; + int col, row, ncol, nrow, id, nline; + char *label; + int haspty, hasframe, mapnl, keepopen, smooth; + char *shf, **sh; + char *argv[sizeof default_shell / sizeof *default_shell]; + char **pp; + + if ((id = findid()) < 0) + return; + row = a->v_type == V_ERR ? 1 : a->v_num; + a++; + col = a->v_type == V_ERR ? 0 : a->v_num; + a++; + nrow = a->v_type == V_ERR ? wwnrow - row : a->v_num; + a++; + ncol = a->v_type == V_ERR ? wwncol - col : a->v_num; + a++; + nline = a->v_type == V_ERR ? default_nline : a->v_num; + a++; + label = a->v_type == V_ERR ? 0 : a->v_str; + if ((haspty = vtobool(++a, 1, -1)) < 0) + return; + if ((hasframe = vtobool(++a, 1, -1)) < 0) + return; + if ((mapnl = vtobool(++a, !haspty, -1)) < 0) + return; + if ((keepopen = vtobool(++a, 0, -1)) < 0) + return; + if ((smooth = vtobool(++a, default_smooth, -1)) < 0) + return; + if ((++a)->v_type != V_ERR) { + for (pp = argv; a->v_type != V_ERR && + pp < &argv[sizeof argv/sizeof *argv-1]; pp++, a++) + *pp = a->v_str; + *pp = 0; + shf = *(sh = argv); + if ((*sh = strrchr(shf, '/'))) + (*sh)++; + else + *sh = shf; + } else { + sh = default_shell; + shf = default_shellfile; + } + if ((w = openwin(id, row, col, nrow, ncol, nline, label, + haspty ? WWT_PTY : WWT_SOCKET, hasframe ? WWU_HASFRAME : 0, shf, + sh)) == 0) + return; + if (mapnl) + SET(w->ww_wflags, WWW_MAPNL); + else + CLR(w->ww_wflags, WWW_MAPNL); + if (keepopen) + SET(w->ww_uflags, WWU_KEEPOPEN); + else + CLR(w->ww_uflags, WWU_KEEPOPEN); + if (!smooth) + SET(w->ww_wflags, WWW_NOUPDATE); + else + CLR(w->ww_wflags, WWW_NOUPDATE); + v->v_type = V_NUM; + v->v_num = id + 1; +} + +struct lcmd_arg arg_def_nline[] = { + { "nlines", 1, ARG_NUM }, + { 0 } +}; + +void +l_def_nline(v, a) + struct value *v, *a; +{ + v->v_num = default_nline; + v->v_type = V_NUM; + if (a->v_type != V_ERR) + default_nline = a->v_num; +} + +struct lcmd_arg arg_smooth[] = { + { "window", 1, ARG_NUM }, + { "flag", 1, ARG_ANY }, + { 0 } +}; + +void +l_smooth(v, a) + struct value *v, *a; +{ + struct ww *w; + + v->v_type = V_NUM; + v->v_num = 0; + if ((w = vtowin(a++, selwin)) == 0) + return; + v->v_num = ISSET(w->ww_wflags, WWW_NOUPDATE) == 0; + if (!vtobool(a, v->v_num, v->v_num)) + SET(w->ww_wflags, WWW_NOUPDATE); + else + CLR(w->ww_wflags, WWW_NOUPDATE); +} + +struct lcmd_arg arg_def_smooth[] = { + { "flag", 1, ARG_ANY }, + { 0 } +}; + +void +l_def_smooth(v, a) + struct value *v, *a; +{ + v->v_type = V_NUM; + v->v_num = default_smooth; + default_smooth = vtobool(a, v->v_num, v->v_num); +} + +struct lcmd_arg arg_select[] = { + { "window", 1, ARG_NUM }, + { 0 } +}; + +void +l_select(v, a) + struct value *v, *a; +{ + struct ww *w; + + v->v_type = V_NUM; + v->v_num = selwin ? selwin->ww_id + 1 : -1; + if (a->v_type == V_ERR) + return; + if ((w = vtowin(a, (struct ww *)0)) == 0) + return; + setselwin(w); +} + +struct lcmd_arg arg_debug[] = { + { "flag", 1, ARG_ANY }, + { 0 } +}; + +void +l_debug(v, a) + struct value *v, *a; +{ + v->v_type = V_NUM; + v->v_num = debug; + debug = vtobool(a, debug, debug); +} + +struct lcmd_arg arg_escape[] = { + { "escapec", 1, ARG_STR }, + { 0 } +}; + +void +l_escape(v, a) + struct value *v, *a; +{ + char buf[2]; + + buf[0] = escapec; + buf[1] = 0; + if ((v->v_str = str_cpy(buf)) == 0) { + error("Out of memory."); + return; + } + v->v_type = V_STR; + if (a->v_type != V_ERR) + setescape(a->v_str); +} + +struct lcmd_arg arg_label[] = { + { "window", 1, ARG_NUM }, + { "label", 1, ARG_STR }, + { 0 } +}; + +void +l_label(v, a) +struct value *v; + struct value *a; +{ + struct ww *w; + + if ((w = vtowin(a, selwin)) == 0) + return; + if ((++a)->v_type != V_ERR && setlabel(w, a->v_str) < 0) + error("Out of memory."); + reframe(); +} + +struct lcmd_arg arg_foreground[] = { + { "window", 1, ARG_NUM }, + { "flag", 1, ARG_ANY }, + { 0 } +}; + +void +l_foreground(v, a) + struct value *v, *a; +{ + struct ww *w; + char flag; + + if ((w = vtowin(a, selwin)) == 0) + return; + v->v_type = V_NUM; + v->v_num = isfg(w); + flag = vtobool(++a, v->v_num, v->v_num); + if (flag == v->v_num) + return; + deletewin(w); + addwin(w, flag); + reframe(); +} + +struct lcmd_arg arg_terse[] = { + { "flag", 1, ARG_ANY }, + { 0 } +}; + +void +l_terse(v, a) + struct value *v, *a; +{ + v->v_type = V_NUM; + v->v_num = terse; + setterse(vtobool(a, terse, terse)); +} + +struct lcmd_arg arg_source[] = { + { "filename", 1, ARG_STR }, + { 0 } +}; + +void +l_source(v, a) + struct value *v, *a; +{ + v->v_type = V_NUM; + if (a->v_type != V_ERR && dosource(a->v_str) < 0) { + error("Can't open %s.", a->v_str); + v->v_num = -1; + } else + v->v_num = 0; +} + +struct lcmd_arg arg_write[] = { + { "window", 1, ARG_NUM }, + { "", 0, ARG_ANY|ARG_LIST }, + { 0 } +}; + +void +l_write(v, a) + struct value *v; + struct value *a; +{ + char buf[20]; + struct ww *w; + + if ((w = vtowin(a++, selwin)) == 0) + return; + while (a->v_type != V_ERR) { + if (a->v_type == V_NUM) { + (void) sprintf(buf, "%d", a->v_num); + (void) write(w->ww_pty, buf, strlen(buf)); + } else + (void) write(w->ww_pty, a->v_str, strlen(a->v_str)); + if ((++a)->v_type != V_ERR) + (void) write(w->ww_pty, " ", 1); + } +} + +struct lcmd_arg arg_close[] = { + { "window", 1, ARG_ANY|ARG_LIST }, + { 0 } +}; + +void +l_close(v, a) + struct value *v; + struct value *a; +{ + struct ww *w; + + if (a->v_type == V_STR && str_match(a->v_str, "all", 3)) + closewin((struct ww *)0); + else + for (; a->v_type != V_ERR; a++) + if ((w = vtowin(a, (struct ww *)0)) != 0) + closewin(w); +} + +struct lcmd_arg arg_cursormodes[] = { + { "modes", 1, ARG_NUM }, + { 0 } +}; + +void +l_cursormodes(v, a) + struct value *v, *a; +{ + + v->v_type = V_NUM; + v->v_num = wwcursormodes; + if (a->v_type != V_ERR) + wwsetcursormodes(a->v_num); +} + +struct lcmd_arg arg_unset[] = { + { "variable", 1, ARG_ANY }, + { 0 } +}; + +void +l_unset(v, a) + struct value *v, *a; +{ + v->v_type = V_NUM; + switch (a->v_type) { + case V_ERR: + v->v_num = -1; + return; + case V_NUM: + if ((a->v_str = str_itoa(a->v_num)) == 0) { + error("Out of memory."); + v->v_num = -1; + return; + } + a->v_type = V_STR; + break; + } + v->v_num = var_unset(a->v_str); +} + +struct ww * +vtowin(v, w) + struct value *v; + struct ww *w; +{ + switch (v->v_type) { + case V_ERR: + if (w != 0) + return w; + error("No window specified."); + return 0; + case V_STR: + error("%s: No such window.", v->v_str); + return 0; + } + if (v->v_num < 1 || v->v_num > NWINDOW + || (w = window[v->v_num - 1]) == 0) { + error("%d: No such window.", v->v_num); + return 0; + } + return w; +} + +char +vtobool(v, def, err) + struct value *v; + char def, err; +{ + switch (v->v_type) { + case V_NUM: + return v->v_num != 0; + case V_STR: + if (str_match(v->v_str, "true", 1) + || str_match(v->v_str, "on", 2) + || str_match(v->v_str, "yes", 1)) + return 1; + else if (str_match(v->v_str, "false", 1) + || str_match(v->v_str, "off", 2) + || str_match(v->v_str, "no", 1)) + return 0; + else { + error("%s: Illegal boolean value.", v->v_str); + return err; + } + /*NOTREACHED*/ + case V_ERR: + return def; + } + /*NOTREACHED*/ + return (0); +} diff --git a/window/lcmd2.c b/window/lcmd2.c new file mode 100644 index 0000000..8d8b72b --- /dev/null +++ b/window/lcmd2.c @@ -0,0 +1,408 @@ +/* $NetBSD: lcmd2.c,v 1.9 1998/08/25 20:59:42 ross Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)lcmd2.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: lcmd2.c,v 1.9 1998/08/25 20:59:42 ross Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include "defs.h" +#include "window_string.h" +#include "var.h" +#include "lcmd.h" +#include "alias.h" + +int printalias __P((void *, struct var *)); +int printvar __P((void *, struct var *)); +char *strtime __P((struct timeval *t)); + +void +l_iostat(v, a) + struct value *v, *a; +{ + struct ww *w; + + if ((w = openiwin(16, "IO Statistics")) == 0) { + error("Can't open statistics window: %s.", wwerror()); + return; + } + wwprintf(w, "ttflush\twrite\terror\tzero\tchar\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\n", + wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc); + wwprintf(w, "token\tuse\tbad\tsaving\ttotal\tbaud\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d/%d (%.1f/%.1f)\n", + wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc, + wwntokc - wwntoksave ? + (int) ((float) wwbaud * wwntokc / + (wwntokc - wwntoksave)) : + wwbaud, + wwnwrc ? (int) ((float) wwbaud * (wwnwrc + wwntoksave) / + wwnwrc) : + wwbaud, + wwntokc - wwntoksave ? + (float) wwntokc / (wwntokc - wwntoksave) : 1.0, + wwnwrc ? (float) (wwnwrc + wwntoksave) / wwnwrc : 1.0); + wwprintf(w, "wwwrite\tattempt\tchar\n"); + wwprintf(w, "%d\t%d\t%d\n", + wwnwwr, wwnwwra, wwnwwrc); + wwprintf(w, "wwupdat\tline\tmiss\tscan\tclreol\tclreos\tmiss\tline\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", + wwnupdate, wwnupdline, wwnupdmiss, wwnupdscan, wwnupdclreol, + wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline); + wwprintf(w, "select\terror\tzero\n"); + wwprintf(w, "%d\t%d\t%d\n", + wwnselect, wwnselecte, wwnselectz); + wwprintf(w, "read\terror\tzero\tchar\tack\tnack\tstat\terrorc\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", + wwnread, wwnreade, wwnreadz, wwnreadc, wwnreadack, wwnreadnack, + wwnreadstat, wwnreadec); + wwprintf(w, "ptyread\terror\tzero\tcontrol\tdata\tchar\n"); + wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n", + wwnwread, wwnwreade, wwnwreadz, + wwnwreadp, wwnwreadd, wwnwreadc); + waitnl(w); + closeiwin(w); +} + +struct lcmd_arg arg_time[] = { + { "who", 1, ARG_STR }, + { 0 } +}; + +void +l_time(v, a) + struct value *v, *a; +{ + struct ww *w; + struct rusage rusage; + struct timeval timeval; + + if ((w = openiwin(8, "Timing and Resource Usage")) == 0) { + error("Can't open time window: %s.", wwerror()); + return; + } + + (void) gettimeofday(&timeval, (struct timezone *)0); + timersub(&timeval, &starttime, &timeval); + (void) getrusage(a->v_type == V_STR + && str_match(a->v_str, "children", 1) + ? RUSAGE_CHILDREN : RUSAGE_SELF, &rusage); + + wwprintf(w, "%-15s %-15s %-15s\n", + "time", "utime", "stime"); + wwprintf(w, "%-15s ", strtime(&timeval)); + wwprintf(w, "%-15s ", strtime(&rusage.ru_utime)); + wwprintf(w, "%-15s\n", strtime(&rusage.ru_stime)); + wwprintf(w, "%-15s %-15s %-15s %-15s\n", + "maxrss", "ixrss", "idrss", "isrss"); + wwprintf(w, "%-15ld %-15ld %-15ld %-15ld\n", + rusage.ru_maxrss, rusage.ru_ixrss, + rusage.ru_idrss, rusage.ru_isrss); + wwprintf(w, "%-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s\n", + "minflt", "majflt", "nswap", "inblk", "oublk", + "msgsnd", "msgrcv", "nsigs", "nvcsw", "nivcsw"); + wwprintf(w, "%-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld\n", + rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap, + rusage.ru_inblock, rusage.ru_oublock, + rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals, + rusage.ru_nvcsw, rusage.ru_nivcsw); + + waitnl(w); + closeiwin(w); +} + +char * +strtime(t) + struct timeval *t; +{ + char fill = 0; + static char buf[20]; + char *p = buf; + + if (t->tv_sec > 60*60) { + (void) sprintf(p, "%ld:", (long int)t->tv_sec / (60*60)); + while (*p++) + ; + p--; + t->tv_sec %= 60*60; + fill++; + } + if (t->tv_sec > 60) { + (void) sprintf(p, fill ? "%02ld:" : "%ld:", t->tv_sec / 60); + while (*p++) + ; + p--; + t->tv_sec %= 60; + fill++; + } + (void) sprintf(p, fill ? "%02ld.%02d" : "%ld.%02ld", + t->tv_sec, t->tv_usec / 10000); + return buf; +} + +void +l_list(v, a) + struct value *v, *a; +{ + struct ww *w, *wp; + int i; + int n; + + for (n = 0, i = 0; i < NWINDOW; i++) + if (window[i] != 0) + n++; + if (n == 0) { + error("No windows."); + return; + } + if ((w = openiwin(n + 2, "Windows")) == 0) { + error("Can't open listing window: %s.", wwerror()); + return; + } + for (i = 0; i < NWINDOW; i++) { + if ((wp = window[i]) == 0) + continue; + wwprintf(w, "%c %c %-13s %-.*s\n", + wp == selwin ? '+' : (wp == lastselwin ? '-' : ' '), + i + '1', + wp->ww_state == WWS_HASPROC ? "" : "(No process)", + wwncol - 20, + wp->ww_label ? wp->ww_label : "(No label)"); + } + waitnl(w); + closeiwin(w); +} + +void +l_variable(v, a) + struct value *v, *a; +{ + struct ww *w; + + if ((w = openiwin(wwnrow - 3, "Variables")) == 0) { + error("Can't open variable window: %s.", wwerror()); + return; + } + if (var_walk(printvar, (void *)w) >= 0) + waitnl(w); + closeiwin(w); +} + +int +printvar(vw, r) + void *vw; + struct var *r; +{ + struct ww *w = vw; + if (more(w, 0) == 2) + return -1; + wwprintf(w, "%16s ", r->r_name); + switch (r->r_val.v_type) { + case V_STR: + wwprintf(w, "%s\n", r->r_val.v_str); + break; + case V_NUM: + wwprintf(w, "%d\n", r->r_val.v_num); + break; + case V_ERR: + wwprintf(w, "ERROR\n"); + break; + } + return 0; +} + +struct lcmd_arg arg_def_shell[] = { + { "", 0, ARG_ANY|ARG_LIST }, + { 0 } +}; + +void +l_def_shell(v, a) + struct value *v, *a; +{ + char **pp; + struct value *vp; + + if (a->v_type == V_ERR) { + if ((v->v_str = str_cpy(default_shellfile)) != 0) + v->v_type = V_STR; + return; + } + if ((v->v_str = default_shellfile)) { + v->v_type = V_STR; + for (pp = default_shell + 1; *pp; pp++) { + str_free(*pp); + *pp = 0; + } + } + for (pp = default_shell, vp = a; + vp->v_type != V_ERR && + pp < &default_shell[sizeof default_shell/sizeof *default_shell-1]; + pp++, vp++) + if ((*pp = vp->v_type == V_STR ? + str_cpy(vp->v_str) : str_itoa(vp->v_num)) == 0) { + /* just leave default_shell[] the way it is */ + p_memerror(); + break; + } + if ((default_shellfile = *default_shell)) { + if ((*default_shell = strrchr(default_shellfile, '/'))) + (*default_shell)++; + else + *default_shell = default_shellfile; + } +} + +struct lcmd_arg arg_alias[] = { + { "", 0, ARG_STR }, + { "", 0, ARG_STR|ARG_LIST }, + { 0 } +}; + +void +l_alias(v, a) + struct value *v, *a; +{ + if (a->v_type == V_ERR) { + struct ww *w; + + if ((w = openiwin(wwnrow - 3, "Aliases")) == 0) { + error("Can't open alias window: %s.", wwerror()); + return; + } + if (alias_walk(printalias, (void *)w) >= 0) + waitnl(w); + closeiwin(w); + } else { + struct alias *ap = 0; + + if ((ap = alias_lookup(a->v_str))) { + if ((v->v_str = str_cpy(ap->a_buf)) == 0) { + p_memerror(); + return; + } + v->v_type = V_STR; + } + if (a[1].v_type == V_STR) { + struct value *vp; + char *p, *q; + char *str; + int n; + + for (n = 0, vp = a + 1; vp->v_type != V_ERR; vp++, n++) + for (p = vp->v_str; *p; p++, n++) + ; + if ((str = str_alloc(n)) == 0) { + p_memerror(); + return; + } + for (q = str, vp = a + 1; vp->v_type != V_ERR; + vp++, q[-1] = ' ') + for (p = vp->v_str; (*q++ = *p++);) + ; + q[-1] = 0; + if ((ap = alias_set(a[0].v_str, (char *)0)) == 0) { + p_memerror(); + str_free(str); + return; + } + ap->a_buf = str; + } + } +} + +int +printalias(vw, a) + void *vw; + struct alias *a; +{ + struct ww *w = vw; + if (more(w, 0) == 2) + return -1; + wwprintf(w, "%16s %s\n", a->a_name, a->a_buf); + return 0; +} + +struct lcmd_arg arg_unalias[] = { + { "alias", 1, ARG_STR }, + { 0 } +}; + +void +l_unalias(v, a) + struct value *v, *a; +{ + if (a->v_type == ARG_STR) + v->v_num = alias_unset(a->v_str); + v->v_type = V_NUM; +} + +struct lcmd_arg arg_echo[] = { + { "window", 1, ARG_NUM }, + { "", 0, ARG_ANY|ARG_LIST }, + { 0 } +}; + +void +l_echo(v, a) + struct value *v, *a; +{ + char buf[20]; + struct ww *w; + + if ((w = vtowin(a++, selwin)) == 0) + return; + while (a->v_type != V_ERR) { + if (a->v_type == V_NUM) { + (void) sprintf(buf, "%d", a->v_num); + (void) wwwrite(w, buf, strlen(buf)); + } else + (void) wwwrite(w, a->v_str, strlen(a->v_str)); + if ((++a)->v_type != V_ERR) + (void) wwwrite(w, " ", 1); + } + (void) wwwrite(w, "\r\n", 2); +} diff --git a/window/local.h b/window/local.h new file mode 100644 index 0000000..435b5fa --- /dev/null +++ b/window/local.h @@ -0,0 +1,53 @@ +/* $NetBSD: local.h,v 1.3 1995/09/28 10:34:26 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)local.h 8.1 (Berkeley) 6/6/93 + */ + +/* + * Things of local interest. + */ + +#define RUNCOM ".windowrc" +#define ESCAPEC ctrl('p') +#define NLINE 48 /* default text buffer size */ + +#ifdef TERMINFO +#define _PATH_CAPTOINFO "/usr/5bin/captoinfo" +#define _PATH_TIC "/usr/5bin/tic" +#define _PATH_RM "/bin/rm" +#endif diff --git a/window/main.c b/window/main.c new file mode 100644 index 0000000..e0f4544 --- /dev/null +++ b/window/main.c @@ -0,0 +1,207 @@ +/* $NetBSD: main.c,v 1.8 1998/02/03 04:27:35 perry Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 4/2/94"; +#else +__RCSID("$NetBSD: main.c,v 1.8 1998/02/03 04:27:35 perry Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include + +#include "defs.h" +#include "window_string.h" +#include "char.h" +#include "local.h" + +int main __P((int, char **)); +void usage __P((void)); + +extern char *__progname; /* from crt0.o */ + +int +main(argc, argv) + int argc; + char **argv; +{ + char *p; + char fflag = 0; + char dflag = 0; + char xflag = 0; + char *cmd = 0; + char tflag = 0; + int ch; + + escapec = ESCAPEC; + debug = strcmp(__progname, "a.out") == 0; + while ((ch = getopt(argc, argv, "fc:e:tdDx")) != -1) { + switch (ch) { + case 'f': + fflag++; + break; + case 'c': + if (cmd != 0) { + warnx("Only one -c allowed"); + usage(); + } + cmd = optarg; + break; + case 'e': + setescape(optarg); + break; + case 't': + tflag++; + break; + case 'd': + dflag++; + break; + case 'D': + debug = !debug; + break; + case 'x': + xflag++; + break; + default: + usage(); + } + } + if ((p = getenv("SHELL")) == 0) + p = _PATH_BSHELL; + if ((default_shellfile = str_cpy(p)) == 0) + errx(1, "Out of memory."); + if ((p = strrchr(default_shellfile, '/'))) + p++; + else + p = default_shellfile; + default_shell[0] = p; + default_shell[1] = 0; + default_nline = NLINE; + default_smooth = 1; + (void) gettimeofday(&starttime, (struct timezone *)0); + if (wwinit() < 0) + errx(1, "%s", wwerror()); + +#ifdef OLD_TTY + if (debug) + wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; + if (xflag) { + wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc; + wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc; + } +#else + if (debug) { + wwnewtty.ww_termios.c_cc[VQUIT] = + wwoldtty.ww_termios.c_cc[VQUIT]; + wwnewtty.ww_termios.c_lflag |= ISIG; + } + if (xflag) { + wwnewtty.ww_termios.c_cc[VSTOP] = + wwoldtty.ww_termios.c_cc[VSTOP]; + wwnewtty.ww_termios.c_cc[VSTART] = + wwoldtty.ww_termios.c_cc[VSTART]; + wwnewtty.ww_termios.c_iflag |= IXON; + } +#endif + if (debug || xflag) + (void) wwsettty(0, &wwnewtty); + + if ((cmdwin = wwopen(WWT_INTERNAL, wwbaud > 2400 ? WWO_REVERSE : 0, 1, + wwncol, 0, 0, 0)) == 0) { + wwflush(); + warnx("%s.\r", wwerror()); + goto bad; + } + SET(cmdwin->ww_wflags, + WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL); + if ((framewin = wwopen(WWT_INTERNAL, WWO_GLASS|WWO_FRAME, wwnrow, + wwncol, 0, 0, 0)) == 0) { + wwflush(); + warnx("%s.\r", wwerror()); + goto bad; + } + wwadd(framewin, &wwhead); + if ((boxwin = wwopen(WWT_INTERNAL, WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) + == 0) { + wwflush(); + warnx("%s.\r", wwerror()); + goto bad; + } + fgwin = framewin; + + wwupdate(); + wwflush(); + setvars(); + + setterse(tflag); + setcmd(1); + if (cmd != 0) + (void) dolongcmd(cmd, (struct value *)0, 0); + if (!fflag) + if (dflag || doconfig() < 0) + dodefault(); + if (selwin != 0) + setcmd(0); + + mloop(); + +bad: + wwend(1); + return 0; +} + +void +usage() +{ + (void) fprintf(stderr, + "Usage: %s [-e escape-char] [-c command] [-t] [-f] [-d]\n", + __progname); + exit(1); +} diff --git a/window/mloop.c b/window/mloop.c new file mode 100644 index 0000000..d2848c5 --- /dev/null +++ b/window/mloop.c @@ -0,0 +1,96 @@ +/* $NetBSD: mloop.c,v 1.6 1997/11/21 08:36:08 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)mloop.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: mloop.c,v 1.6 1997/11/21 08:36:08 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "defs.h" + +void +mloop() +{ + while (!quit) { + if (incmd) { + docmd(); + } else if (wwcurwin->ww_state != WWS_HASPROC) { + if (!ISSET(wwcurwin->ww_uflags, WWU_KEEPOPEN)) + closewin(wwcurwin); + setcmd(1); + if (wwpeekc() == escapec) + (void) wwgetc(); + error("Process died."); + } else { + struct ww *w = wwcurwin; + char *p; + int n; + + if (wwibp >= wwibq) { + wwibp = wwibq = wwib; + wwiomux(); + } + for (p = wwibp; p < wwibq && wwmaskc(*p) != escapec; + p++) + ; + if ((n = p - wwibp) > 0) { + if (w->ww_type != WWT_PTY && + ISSET(w->ww_pflags, WWP_STOPPED)) + startwin(w); +#if defined(sun) && !defined(BSD) + /* workaround for SunOS pty bug */ + while (--n >= 0) + (void) write(w->ww_pty, wwibp++, 1); +#else + (void) write(w->ww_pty, wwibp, n); + wwibp = p; +#endif + } + if (wwpeekc() == escapec) { + (void) wwgetc(); + setcmd(1); + } + } + } +} diff --git a/window/parser.h b/window/parser.h new file mode 100644 index 0000000..e1a8ec5 --- /dev/null +++ b/window/parser.h @@ -0,0 +1,65 @@ +/* $NetBSD: parser.h,v 1.4 1997/11/21 08:36:09 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)parser.h 8.1 (Berkeley) 6/6/93 + */ + +#include "context.h" +#include "token.h" +#include "window_string.h" + +#define p_erred() (cx.x_erred) +#define p_synerred() (cx.x_synerred) +#define p_clearerr() (cx.x_erred = cx.x_synerred = 0) +#define p_abort() (cx.x_abort) + +int p_assign __P((char *, struct value *, int)); +int p_convstr __P((struct value *v)); +void p_error __P((const char *msg, ...)); +int p_expr __P((struct value *, char)); +int p_expr0 __P((struct value *, char)); +int p_expr1 __P((struct value *, char)); +int p_expr11 __P((struct value *, char)); +int p_expr12 __P((struct value *, char)); +int p_expr2 __P((struct value *, char)); +int p_expr3_10 __P((int, struct value *, char)); +int p_expression __P((char)); +int p_function __P((char *, struct value *, int)); +int p_if __P((char)); +int p_statement __P((char)); +void p_statementlist __P((char)); +void p_synerror __P((void)); diff --git a/window/parser1.c b/window/parser1.c new file mode 100644 index 0000000..b6f2249 --- /dev/null +++ b/window/parser1.c @@ -0,0 +1,249 @@ +/* $NetBSD: parser1.c,v 1.4 1997/11/21 08:36:11 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser1.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: parser1.c,v 1.4 1997/11/21 08:36:11 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "parser.h" + +void +p_start() +{ + char flag = 1; + + (void) s_gettok(); + for (;;) { + p_statementlist(flag); + if (token == T_EOF || p_abort()) + break; + flag = 0; + p_synerror(); + while (token != T_EOL && token != T_EOF) { + if (token == T_STR) + str_free(token_str); + (void) s_gettok(); + } + if (token == T_EOL) + (void) s_gettok(); + p_clearerr(); + } +} + +void +p_statementlist(flag) + char flag; +{ + for (; p_statement(flag) >= 0; p_clearerr()) + ; +} + +int +p_statement(flag) + char flag; +{ + switch (token) { + case T_EOL: + (void) s_gettok(); + return 0; + case T_IF: + return p_if(flag); + default: + return p_expression(flag); + } +} + +int +p_if(flag) + char flag; +{ + struct value t; + char true = 0; + +top: + (void) s_gettok(); + + if (p_expr(&t, flag) < 0) { + p_synerror(); + return -1; + } + switch (t.v_type) { + case V_NUM: + true = !true && t.v_num != 0; + break; + case V_STR: + p_error("if: Numeric value required."); + str_free(t.v_str); + case V_ERR: + flag = 0; + break; + } + + if (token != T_THEN) { + p_synerror(); + return -1; + } + + (void) s_gettok(); + p_statementlist(flag && true); + if (p_erred()) + return -1; + + if (token == T_ELSIF) + goto top; + + if (token == T_ELSE) { + (void) s_gettok(); + p_statementlist(flag && !true); + if (p_erred()) + return -1; + } + + if (token == T_ENDIF) { + (void) s_gettok(); + return 0; + } + + p_synerror(); + return -1; +} + +int +p_expression(flag) + char flag; +{ + struct value t; + char *cmd; + + switch (token) { + case T_NUM: + t.v_type = V_NUM; + t.v_num = token_num; + (void) s_gettok(); + break; + case T_STR: + t.v_type = V_STR; + t.v_str = token_str; + (void) s_gettok(); + break; + default: + if (p_expr(&t, flag) < 0) + return -1; + if (token == T_EOF) { + val_free(t); + return 0; + } + } + if (token != T_ASSIGN && p_convstr(&t) < 0) + return -1; + cmd = t.v_type == V_STR ? t.v_str : 0; + if ((*(token == T_ASSIGN ? p_assign : p_function))(cmd, &t, flag) < 0) { + if (cmd) + str_free(cmd); + return -1; + } + if (cmd) + str_free(cmd); + val_free(t); + if (token == T_EOL) + (void) s_gettok(); + else if (token != T_EOF) { + p_synerror(); + return -1; + } + return 0; +} + +int +p_convstr(v) + struct value *v; +{ + if (v->v_type != V_NUM) + return 0; + if ((v->v_str = str_itoa(v->v_num)) == 0) { + p_memerror(); + v->v_type = V_ERR; + return -1; + } + v->v_type = V_STR; + return 0; +} + +void +p_synerror() +{ + if (!cx.x_synerred) { + cx.x_synerred = cx.x_erred = 1; + error("Syntax error."); + } +} + +void +#if __STDC__ +p_error(const char *msg, ...) +#else +p_error(msg, ..) + char *msg; + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, msg); +#else + va_start(ap); +#endif + if (!cx.x_erred) { + cx.x_erred = 1; + verror(msg, ap); + } + va_end(ap); +} + +void +p_memerror() +{ + cx.x_erred = cx.x_abort = 1; + error("Out of memory."); +} diff --git a/window/parser2.c b/window/parser2.c new file mode 100644 index 0000000..963b8b9 --- /dev/null +++ b/window/parser2.c @@ -0,0 +1,247 @@ +/* $NetBSD: parser2.c,v 1.5 1998/08/25 20:59:42 ross Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser2.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: parser2.c,v 1.5 1998/08/25 20:59:42 ross Exp $"); +#endif +#endif /* not lint */ + +#define EXTERN +#include "ww.h" +#include "defs.h" +#include "alias.h" +#undef EXTERN +#include "parser.h" +#include "var.h" +#include "lcmd.h" + +/* + * name == 0 means we don't have a function name but + * want to parse the arguments anyway. flag == 0 in this case. + */ +int +p_function(name, v, flag) + char *name; + struct value *v; + int flag; +{ + struct value t; + struct lcmd_tab *c = 0; + struct alias *a = 0; + struct lcmd_arg *ap; /* this arg */ + struct lcmd_arg *lp = 0; /* list arg */ + int i; + struct value av[LCMD_NARG + 1]; + struct value *vp; + + if (name != 0) { + if ((c = lcmd_lookup(name))) + name = c->lc_name; + else if ((a = alias_lookup(name))) + name = a->a_name; + else { + p_error("%s: No such command or alias.", name); + flag = 0; + } + } + for (vp = av; vp < &av[LCMD_NARG + 1]; vp++) + vp->v_type = V_ERR; + + if (token == T_LP) + (void) s_gettok(); + i = 0; + for (;;) { + ap = 0; + vp = 0; + if (token == T_COMMA) /* null argument */ + t.v_type = V_ERR; + else { + if (p_expr0(&t, flag) < 0) + break; + if (t.v_type == V_ERR) + flag = 0; + } + if (token != T_ASSIGN) { + if (i >= LCMD_NARG || + (c != 0 && (ap = lp) == 0 && + (ap = c->lc_arg + i)->arg_name == 0)) { + p_error("%s: Too many arguments.", name); + flag = 0; + } else + vp = &av[i++]; + } else { + char *tmp; + if (p_convstr(&t) < 0) + goto abort; + tmp = t.v_type == V_STR ? t.v_str : 0; + (void) s_gettok(); + if (p_expr(&t, flag) < 0) { + if (tmp) + str_free(tmp); + p_synerror(); + goto abort; + } + if (t.v_type == V_ERR) + flag = 0; + if (tmp) { + if (c == 0) { + /* an aliase */ + p_error("%s: Bad alias syntax.", name); + flag = 0; + } else { + for (ap = c->lc_arg, vp = av; + ap != 0 && ap->arg_name != 0 && + (*ap->arg_name == '\0' || + !str_match(tmp, ap->arg_name, + ap->arg_minlen)); + ap++, vp++) + ; + if (ap == 0 || ap->arg_name == 0) { + p_error("%s: Unknown argument \"%s\".", + name, tmp); + flag = 0; + ap = 0; + vp = 0; + } + } + str_free(tmp); + } + } + if (ap != 0) { + if (ap->arg_flags & ARG_LIST) { + i = vp - av + 1; + lp = ap; + } + if (vp->v_type != V_ERR) { + if (*ap->arg_name) + p_error("%s: Argument %d (%s) duplicated.", + name, vp - av + 1, + ap->arg_name); + else + p_error("%s: Argument %d duplicated.", + name, vp - av + 1); + flag = 0; + vp = 0; + } else if (t.v_type == V_ERR) { + /* do nothing */ + } else if (((ap->arg_flags&ARG_TYPE) == ARG_NUM && + t.v_type != V_NUM) || + ((ap->arg_flags&ARG_TYPE) == ARG_STR && + t.v_type != V_STR)) { + if (*ap->arg_name) + p_error("%s: Argument %d (%s) type mismatch.", + name, vp - av + 1, + ap->arg_name); + else + p_error("%s: Argument %d type mismatch.", + name, vp - av + 1); + flag = 0; + vp = 0; + } + } + if (vp != 0) + *vp = t; + else + val_free(t); + if (token == T_COMMA) + (void) s_gettok(); + } + + if (p_erred()) + flag = 0; + if (token == T_RP) + (void) s_gettok(); + else if (token != T_EOL && token != T_EOF) + flag = 0; /* look for legal follow set */ + v->v_type = V_ERR; + if (flag) { + if (c != 0) + (*c->lc_func)(v, av); + else { + if (a->a_flags & A_INUSE) + p_error("%s: Recursive alias.", a->a_name); + else { + a->a_flags |= A_INUSE; + if (dolongcmd(a->a_buf, av, i) < 0) + p_memerror(); + a->a_flags &= ~A_INUSE; + } + } + } + if (p_abort()) { + val_free(*v); + v->v_type = V_ERR; + goto abort; + } + for (vp = av; vp < &av[LCMD_NARG]; vp++) + val_free(*vp); + return 0; +abort: + for (vp = av; vp < &av[LCMD_NARG]; vp++) + val_free(*vp); + return -1; +} + +int +p_assign(name, v, flag) + char *name; + struct value *v; + char flag; +{ + (void) s_gettok(); + + if (p_expr(v, flag) < 0) { + p_synerror(); + return -1; + } + switch (v->v_type) { + case V_STR: + case V_NUM: + if (flag && var_set(name, v) == 0) { + p_memerror(); + val_free(*v); + return -1; + } + break; + } + return 0; +} diff --git a/window/parser3.c b/window/parser3.c new file mode 100644 index 0000000..fd3104e --- /dev/null +++ b/window/parser3.c @@ -0,0 +1,203 @@ +/* $NetBSD: parser3.c,v 1.4 1997/11/21 08:36:14 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser3.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: parser3.c,v 1.4 1997/11/21 08:36:14 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "parser.h" + +/* + * = + * ? : + * || + * && + * | + * ^ + * & + * == != + * <= >= + * << >> + * + - + * * / % + * unary - + ~ ! + */ +int +p_expr(v, flag) + struct value *v; + char flag; +{ + struct value t; + int ret; + + if (p_expr0(&t, flag) < 0) + return -1; + + if (token != T_ASSIGN) { + *v = t; + return 0; + } + switch (t.v_type) { + case V_NUM: + p_error("%d: Not a variable.", t.v_num); + case V_ERR: + t.v_str = 0; + break; + } + ret = p_assign(t.v_str, v, flag); + if (t.v_str != 0) + str_free(t.v_str); + return ret; +} + +/* + * ? : + */ +int +p_expr0(v, flag) + struct value *v; + char flag; +{ + struct value t; + char true = 0; + + if (p_expr1(v, flag) < 0) + return -1; + if (token != T_QUEST) + return 0; + switch (v->v_type) { + case V_NUM: + true = v->v_num != 0; + break; + case V_STR: + p_error("?: Numeric left operand required."); + str_free(v->v_str); + v->v_type = V_ERR; + case V_ERR: + flag = 0; + break; + } + (void) s_gettok(); + v->v_type = V_ERR; + if ((flag && true ? p_expr1(v, 1) : p_expr1(&t, 0)) < 0) + return -1; + if (token != T_COLON) { + val_free(*v); + p_synerror(); + return -1; + } + (void) s_gettok(); + return flag && !true ? p_expr1(v, 1) : p_expr1(&t, 0); +} + +/* + * || + */ +int +p_expr1(v, flag) + struct value *v; + char flag; +{ + char true = 0; + + if (p_expr2(v, flag) < 0) + return -1; + if (token != T_OROR) + return 0; + for (;;) { + switch (v->v_type) { + case V_NUM: + v->v_num = true = true || v->v_num != 0; + break; + case V_STR: + p_error("||: Numeric operands required."); + str_free(v->v_str); + v->v_type = V_ERR; + case V_ERR: + flag = 0; + break; + } + if (token != T_OROR) + return 0; + (void) s_gettok(); + if (p_expr2(v, flag && !true) < 0) + return -1; + } +} + +/* + * && + */ +int +p_expr2(v, flag) + struct value *v; + char flag; +{ + char true = 1; + + if (p_expr3_10(3, v, flag) < 0) + return -1; + if (token != T_ANDAND) + return 0; + for (;;) { + switch (v->v_type) { + case V_NUM: + v->v_num = true = true && v->v_num != 0; + break; + case V_STR: + p_error("&&: Numeric operands required."); + str_free(v->v_str); + v->v_type = V_ERR; + case V_ERR: + flag = 0; + break; + } + if (token != T_ANDAND) + return 0; + (void) s_gettok(); + if (p_expr3_10(3, v, flag && true) < 0) + return -1; + } + /*NOTREACHED*/ +} diff --git a/window/parser4.c b/window/parser4.c new file mode 100644 index 0000000..07782c2 --- /dev/null +++ b/window/parser4.c @@ -0,0 +1,307 @@ +/* $NetBSD: parser4.c,v 1.6 1997/11/21 08:36:15 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser4.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: parser4.c,v 1.6 1997/11/21 08:36:15 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "defs.h" +#include "parser.h" + +/* + * | 3 + * ^ 4 + * & 5 + * == != 6 + * < <= > >= 7 + * << >> 8 + * + - 9 + * * / % 10 + */ +int +p_expr3_10(level, v, flag) + int level; + struct value *v; + char flag; +{ + struct value l, r; + int op; + char *opname = 0; + + if ((level == 10 ? p_expr11(v, flag) + : p_expr3_10(level + 1, v, flag)) < 0) + return -1; + for (;;) { + switch (level) { + case 3: + if (token != T_OR) + return 0; + opname = "|"; + break; + case 4: + if (token != T_XOR) + return 0; + opname = "^"; + break; + case 5: + if (token != T_AND) + return 0; + opname = "&"; + break; + case 6: + if (token == T_EQ) + opname = "=="; + else if (token == T_NE) + opname = "!="; + else + return 0; + break; + case 7: + switch (token) { + case T_LT: + opname = "<"; + break; + case T_LE: + opname = "<="; + break; + case T_GT: + opname = ">"; + break; + case T_GE: + opname = ">="; + break; + default: + return 0; + } + break; + case 8: + if (token == T_LS) + opname = "<<"; + else if (token == T_RS) + opname = ">>"; + else + return 0; + break; + case 9: + if (token == T_PLUS) + opname = "+"; + else if (token == T_MINUS) + opname = "-"; + else + return 0; + break; + case 10: + switch (token) { + case T_MUL: + opname = "*"; + break; + case T_DIV: + opname = "/"; + break; + case T_MOD: + opname = "%"; + break; + default: + return 0; + } + break; + } + l = *v; + if (l.v_type == V_ERR) + flag = 0; + + op = token; + (void) s_gettok(); + if ((level == 10 ? p_expr11(&r, flag) + : p_expr3_10(level + 1, &r, flag)) < 0) { + p_synerror(); + val_free(l); + return -1; + } + + if (r.v_type == V_ERR) + flag = 0; + else switch (op) { + case T_EQ: + case T_NE: + case T_LT: + case T_LE: + case T_GT: + case T_GE: + case T_PLUS: + if (l.v_type == V_STR) { + if (r.v_type == V_NUM) + if (p_convstr(&r) < 0) + flag = 0; + } else + if (r.v_type == V_STR) + if (p_convstr(&l) < 0) + flag = 0; + break; + case T_LS: + case T_RS: + if (r.v_type == V_STR) { + char *p = r.v_str; + r.v_type = V_NUM; + r.v_num = strlen(p); + str_free(p); + } + break; + case T_OR: + case T_XOR: + case T_AND: + case T_MINUS: + case T_MUL: + case T_DIV: + case T_MOD: + default: + if (l.v_type == V_STR || r.v_type == V_STR) { + p_error("%s: Numeric operands required.", + opname); + flag = 0; + } + } + if (!flag) { + val_free(l); + val_free(r); + v->v_type = V_ERR; + if (p_abort()) + return -1; + continue; + } + + v->v_type = V_NUM; + switch (op) { + case T_EQ: + case T_NE: + case T_LT: + case T_LE: + case T_GT: + case T_GE: + if (l.v_type == V_STR) { + int tmp = strcmp(l.v_str, r.v_str); + str_free(l.v_str); + str_free(r.v_str); + l.v_type = V_NUM; + l.v_num = tmp; + r.v_type = V_NUM; + r.v_num = 0; + } + break; + } + switch (op) { + case T_OR: + v->v_num = l.v_num | r.v_num; + break; + case T_XOR: + v->v_num = l.v_num ^ r.v_num; + break; + case T_AND: + v->v_num = l.v_num & r.v_num; + break; + case T_EQ: + v->v_num = l.v_num == r.v_num; + break; + case T_NE: + v->v_num = l.v_num != r.v_num; + break; + case T_LT: + v->v_num = l.v_num < r.v_num; + break; + case T_LE: + v->v_num = l.v_num <= r.v_num; + break; + case T_GT: + v->v_num = l.v_num > r.v_num; + break; + case T_GE: + v->v_num = l.v_num >= r.v_num; + break; + case T_LS: + if (l.v_type == V_STR) { + int i; + if ((i = strlen(l.v_str)) > r.v_num) + i = r.v_num; + v->v_str = str_ncpy(l.v_str, i); + v->v_type = V_STR; + } else + v->v_num = l.v_num << r.v_num; + break; + case T_RS: + if (l.v_type == V_STR) { + int i; + if ((i = strlen(l.v_str)) > r.v_num) + i -= r.v_num; + else + i = 0; + v->v_str = str_cpy(l.v_str + i); + v->v_type = V_STR; + } else + v->v_num = l.v_num >> r.v_num; + break; + case T_PLUS: + if (l.v_type == V_STR) { + v->v_str = str_cat(l.v_str, r.v_str); + v->v_type = V_STR; + } else + v->v_num = l.v_num + r.v_num; + break; + case T_MINUS: + v->v_num = l.v_num - r.v_num; + break; + case T_MUL: + v->v_num = l.v_num * r.v_num; + break; + case T_DIV: + v->v_num = l.v_num / r.v_num; + break; + case T_MOD: + v->v_num = l.v_num % r.v_num; + break; + } + val_free(l); + val_free(r); + } + /*NOTREACHED*/ +} diff --git a/window/parser5.c b/window/parser5.c new file mode 100644 index 0000000..6fcc068 --- /dev/null +++ b/window/parser5.c @@ -0,0 +1,211 @@ +/* $NetBSD: parser5.c,v 1.4 1997/11/21 08:36:16 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)parser5.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: parser5.c,v 1.4 1997/11/21 08:36:16 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "parser.h" +#include "var.h" + +/* + * unary $ $? + - ! ~ + */ +int +p_expr11(v, flag) + struct value *v; + char flag; +{ + int op; + char *opname; + + switch (token) { + case T_DOLLAR: + opname = "$"; + break; + case T_DQ: + opname = "$?"; + break; + case T_PLUS: + opname = "unary +"; + break; + case T_MINUS: + opname = "unary -"; + break; + case T_NOT: + opname = "!"; + break; + case T_COMP: + opname = "~"; + break; + default: + return p_expr12(v, flag); + } + op = token; + (void) s_gettok(); + if (p_expr11(v, flag) < 0) + return -1; + switch (v->v_type) { + case V_NUM: + break; + case V_STR: + switch (op) { + case T_MINUS: + case T_NOT: + case T_COMP: + p_error("%s: Numeric operand required.", opname); + str_free(v->v_str); + v->v_type = V_ERR; + return 0; + } + break; + case V_ERR: + return 0; + } + switch (op) { + case T_DOLLAR: + case T_DQ: + if (v->v_type == V_NUM) { + int tmp = cx.x_type == X_BUF && cx.x_arg != 0 && + v->v_num > 0 && v->v_num <= cx.x_narg; + if (op == T_DQ) + v->v_num = tmp; + else if (tmp) + *v = cx.x_arg[v->v_num - 1]; + else { + p_error("%d: No such argument.", v->v_num); + v->v_type = V_ERR; + } + } else { + char *name = v->v_str; + struct var *r = var_lookup(name); + if (op == T_DQ) { + v->v_type = V_NUM; + v->v_num = r != 0; + } else if (r != 0) + *v = r->r_val; + else { + p_error("%s: Undefined variable.", name); + v->v_type = V_ERR; + } + str_free(name); + } + if (v->v_type == V_STR && (v->v_str = str_cpy(v->v_str)) == 0) { + p_memerror(); + return -1; + } + break; + case T_MINUS: + v->v_num = - v->v_num; + break; + case T_NOT: + v->v_num = ! v->v_num; + break; + case T_COMP: + v->v_num = ~ v->v_num; + break; + } + return 0; +} + +/* + * string, number, ( expr ) + * Plus function calls. + * + * Always return v_type == V_ERR when flag == 0. + */ +int +p_expr12(v, flag) + struct value *v; + char flag; +{ + v->v_type = V_ERR; + switch (token) { + case T_NUM: + if (flag) { + v->v_type = V_NUM; + v->v_num = token_num; + } + (void) s_gettok(); + break; + case T_STR: + if (flag) { + v->v_type = V_STR; + v->v_str = token_str; + } else + str_free(token_str); + (void) s_gettok(); + break; + case T_LP: + (void) s_gettok(); + if (p_expr(v, flag) < 0) { + p_synerror(); + return -1; + } + if (token != T_RP) { + p_synerror(); + val_free(*v); + return -1; + } + (void) s_gettok(); + break; + default: + return -1; + } + while (token == T_LP) { + char *cmd; + + if (p_convstr(v) < 0) + return -1; + cmd = v->v_type == V_STR ? v->v_str : 0; + if (p_function(cmd, v, flag) < 0) { + if (cmd) + str_free(cmd); + return -1; + } + if (cmd) + str_free(cmd); + } + return 0; +} diff --git a/window/scanner.c b/window/scanner.c new file mode 100644 index 0000000..ea0ae55 --- /dev/null +++ b/window/scanner.c @@ -0,0 +1,598 @@ +/* $NetBSD: scanner.c,v 1.5 1998/08/25 20:59:43 ross Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)scanner.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: scanner.c,v 1.5 1998/08/25 20:59:43 ross Exp $"); +#endif +#endif /* not lint */ + +#include "defs.h" +#include "token.h" +#include "context.h" +#include "window_string.h" + +int s_getc __P((void)); +int s_gettok1 __P((void)); +int s_ungetc __P((int)); + +int +s_getc() +{ + int c; + + switch (cx.x_type) { + case X_FILE: + c = getc(cx.x_fp); + if (cx.x_bol && c != EOF) { + cx.x_bol = 0; + cx.x_lineno++; + } + if (c == '\n') + cx.x_bol = 1; + return c; + case X_BUF: + if (*cx.x_bufp != 0) + return *cx.x_bufp++ & 0xff; + else + return EOF; + } + /*NOTREACHED*/ + return(0); /* XXX: placate gcc */ +} + +int +s_ungetc(c) + int c; +{ + if (c == EOF) + return EOF; + switch (cx.x_type) { + case X_FILE: + cx.x_bol = 0; + return ungetc(c, cx.x_fp); + case X_BUF: + if (cx.x_bufp > cx.x_buf) + return *--cx.x_bufp = c; + else + return EOF; + } + /*NOTREACHED*/ + return(0); /* XXX: placate gcc */ +} + +int +s_gettok() +{ + char buf[100]; + char *p = buf; + int c; + int state = 0; + +loop: + c = s_getc(); + switch (state) { + case 0: + switch (c) { + case ' ': + case '\t': + break; + case '\n': + case ';': + cx.x_token = T_EOL; + state = -1; + break; + case '#': + state = 1; + break; + case EOF: + cx.x_token = T_EOF; + state = -1; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': case '.': + *p++ = c; + state = 2; + break; + case '"': + state = 3; + break; + case '\'': + state = 4; + break; + case '\\': + switch (c = s_gettok1()) { + case -1: + break; + case -2: + state = 0; + break; + default: + *p++ = c; + state = 2; + } + break; + case '0': + cx.x_val.v_num = 0; + state = 10; + break; + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + cx.x_val.v_num = c - '0'; + state = 11; + break; + case '>': + state = 20; + break; + case '<': + state = 21; + break; + case '=': + state = 22; + break; + case '!': + state = 23; + break; + case '&': + state = 24; + break; + case '|': + state = 25; + break; + case '$': + state = 26; + break; + case '~': + cx.x_token = T_COMP; + state = -1; + break; + case '+': + cx.x_token = T_PLUS; + state = -1; + break; + case '-': + cx.x_token = T_MINUS; + state = -1; + break; + case '*': + cx.x_token = T_MUL; + state = -1; + break; + case '/': + cx.x_token = T_DIV; + state = -1; + break; + case '%': + cx.x_token = T_MOD; + state = -1; + break; + case '^': + cx.x_token = T_XOR; + state = -1; + break; + case '(': + cx.x_token = T_LP; + state = -1; + break; + case ')': + cx.x_token = T_RP; + state = -1; + break; + case ',': + cx.x_token = T_COMMA; + state = -1; + break; + case '?': + cx.x_token = T_QUEST; + state = -1; + break; + case ':': + cx.x_token = T_COLON; + state = -1; + break; + case '[': + cx.x_token = T_LB; + state = -1; + break; + case ']': + cx.x_token = T_RB; + state = -1; + break; + default: + cx.x_val.v_num = c; + cx.x_token = T_CHAR; + state = -1; + break; + } + break; + case 1: /* got # */ + if (c == '\n' || c == EOF) { + (void) s_ungetc(c); + state = 0; + } + break; + case 2: /* unquoted string */ + switch (c) { + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '_': case '.': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (p < buf + sizeof buf - 1) + *p++ = c; + break; + case '"': + state = 3; + break; + case '\'': + state = 4; + break; + case '\\': + switch (c = s_gettok1()) { + case -2: + (void) s_ungetc(' '); + case -1: + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + } + break; + default: + (void) s_ungetc(c); + case EOF: + *p = 0; + cx.x_token = T_STR; + switch (*buf) { + case 'i': + if (buf[1] == 'f' && buf[2] == 0) + cx.x_token = T_IF; + break; + case 't': + if (buf[1] == 'h' && buf[2] == 'e' + && buf[3] == 'n' && buf[4] == 0) + cx.x_token = T_THEN; + break; + case 'e': + if (buf[1] == 'n' && buf[2] == 'd' + && buf[3] == 'i' && buf[4] == 'f' + && buf[5] == 0) + cx.x_token = T_ENDIF; + else { + if (buf[1] == 'l' && buf[2] == 's') { + if (buf[3] == 'i' + && buf[4] == 'f' + && buf[5] == 0) + cx.x_token = T_ELSIF; + else { + if (buf[3] == 'e' + && buf[4] == 0) + cx.x_token = + T_ELSE; + } + } + } + break; + } + if (cx.x_token == T_STR + && (cx.x_val.v_str = str_cpy(buf)) == 0) { + p_memerror(); + cx.x_token = T_EOF; + } + state = -1; + break; + } + break; + case 3: /* " quoted string */ + switch (c) { + case '\n': + (void) s_ungetc(c); + case EOF: + case '"': + state = 2; + break; + case '\\': + switch (c = s_gettok1()) { + case -1: + case -2: /* newlines are invisible */ + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + } + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + break; + } + break; + case 4: /* ' quoted string */ + switch (c) { + case '\n': + (void) s_ungetc(c); + case EOF: + case '\'': + state = 2; + break; + case '\\': + switch (c = s_gettok1()) { + case -1: + case -2: /* newlines are invisible */ + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + } + break; + default: + if (p < buf + sizeof buf - 1) + *p++ = c; + break; + } + break; + case 10: /* got 0 */ + switch (c) { + case 'x': + case 'X': + cx.x_val.v_num = 0; + state = 12; + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + cx.x_val.v_num = c - '0'; + state = 13; + break; + case '8': case '9': + cx.x_val.v_num = c - '0'; + state = 11; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 11: /* decimal number */ + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + cx.x_val.v_num = cx.x_val.v_num * 10 + c - '0'; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 12: /* hex number */ + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + cx.x_val.v_num = cx.x_val.v_num * 16 + c - '0'; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'a' + 10; + break; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'A' + 10; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 13: /* octal number */ + switch (c) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + cx.x_val.v_num = cx.x_val.v_num * 8 + c - '0'; + break; + default: + (void) s_ungetc(c); + state = -1; + cx.x_token = T_NUM; + } + break; + case 20: /* got > */ + switch (c) { + case '=': + cx.x_token = T_GE; + state = -1; + break; + case '>': + cx.x_token = T_RS; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_GT; + state = -1; + } + break; + case 21: /* got < */ + switch (c) { + case '=': + cx.x_token = T_LE; + state = -1; + break; + case '<': + cx.x_token = T_LS; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_LT; + state = -1; + } + break; + case 22: /* got = */ + switch (c) { + case '=': + cx.x_token = T_EQ; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_ASSIGN; + state = -1; + } + break; + case 23: /* got ! */ + switch (c) { + case '=': + cx.x_token = T_NE; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_NOT; + state = -1; + } + break; + case 24: /* got & */ + switch (c) { + case '&': + cx.x_token = T_ANDAND; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_AND; + state = -1; + } + break; + case 25: /* got | */ + switch (c) { + case '|': + cx.x_token = T_OROR; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_OR; + state = -1; + } + break; + case 26: /* got $ */ + switch (c) { + case '?': + cx.x_token = T_DQ; + state = -1; + break; + default: + (void) s_ungetc(c); + cx.x_token = T_DOLLAR; + state = -1; + } + break; + default: + abort(); + } + if (state >= 0) + goto loop; + return cx.x_token; +} + +int +s_gettok1() +{ + int c; + int n; + + c = s_getc(); /* got \ */ + switch (c) { + case EOF: + return -1; + case '\n': + return -2; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + default: + return c; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': + break; + } + n = c - '0'; + c = s_getc(); /* got \[0-7] */ + if (c < '0' || c > '7') { + (void) s_ungetc(c); + return n; + } + n = n * 8 + c - '0'; + c = s_getc(); /* got \[0-7][0-7] */ + if (c < '0' || c > '7') { + (void) s_ungetc(c); + return n; + } + return n * 8 + c - '0'; +} diff --git a/window/startup.c b/window/startup.c new file mode 100644 index 0000000..1a23e8b --- /dev/null +++ b/window/startup.c @@ -0,0 +1,104 @@ +/* $NetBSD: startup.c,v 1.5 1997/11/21 08:36:19 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)startup.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: startup.c,v 1.5 1997/11/21 08:36:19 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "defs.h" +#include "var.h" +#include "char.h" +#include "local.h" + +int +doconfig() +{ + char buf[100]; + char *home; + static char runcom[] = RUNCOM; + + if ((home = getenv("HOME")) == 0) + home = "."; + (void) sprintf(buf, "%.*s/%s", + (int)((sizeof buf - sizeof runcom) / sizeof (char) - 1), + home, runcom); + return dosource(buf); +} + +/* + * The default is two windows of equal size. + */ +void +dodefault() +{ + struct ww *w; + int r = wwnrow / 2 - 1; + + if (openwin(1, r + 2, 0, wwnrow - r - 2, wwncol, default_nline, + (char *) 0, WWT_PTY, WWU_HASFRAME, default_shellfile, + default_shell) == 0) + return; + if ((w = openwin(0, 1, 0, r, wwncol, default_nline, + (char *) 0, WWT_PTY, WWU_HASFRAME, default_shellfile, + default_shell)) == 0) + return; + wwprintf(w, "Escape character is %s.\r\n", unctrl(escapec)); +} + +void +setvars() +{ + /* try to use a random ordering to balance the tree */ + (void) var_setnum("nrow", wwnrow); + (void) var_setnum("ncol", wwncol); + (void) var_setnum("baud", wwbaud); + (void) var_setnum("m_rev", WWM_REV); + (void) var_setnum("m_blk", WWM_BLK); + (void) var_setnum("m_ul", WWM_UL); + (void) var_setnum("m_grp", WWM_GRP); + (void) var_setnum("m_dim", WWM_DIM); + (void) var_setnum("m_usr", WWM_USR); + (void) var_setstr("term", wwterm); + (void) var_setnum("modes", wwavailmodes); +} diff --git a/window/string.c b/window/string.c new file mode 100644 index 0000000..7a59021 --- /dev/null +++ b/window/string.c @@ -0,0 +1,165 @@ +/* $NetBSD: string.c,v 1.6 1997/11/21 08:36:20 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)string.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: string.c,v 1.6 1997/11/21 08:36:20 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#define EXTERN +#include "window_string.h" +#undef EXTERN + +char * +str_cpy(s) + char *s; +{ + char *str; + char *p; + + str = p = str_alloc(strlen(s) + 1); + if (p == 0) + return 0; + while ((*p++ = *s++)) + ; + return str; +} + +char * +str_ncpy(s, n) + char *s; + int n; +{ + int l = strlen(s); + char *str; + char *p; + + if (n > l) + n = l; + str = p = str_alloc(n + 1); + if (p == 0) + return 0; + while (--n >= 0) + *p++ = *s++; + *p = 0; + return str; +} + +char * +str_itoa(i) + int i; +{ + char buf[30]; + + (void) snprintf(buf, sizeof(buf), "%d", i); + return str_cpy(buf); +} + +char * +str_cat(s1, s2) + char *s1, *s2; +{ + char *str; + char *p, *q; + + str = p = str_alloc(strlen(s1) + strlen(s2) + 1); + if (p == 0) + return 0; + for (q = s1; (*p++ = *q++);) + ; + for (q = s2, p--; (*p++ = *q++);) + ; + return str; +} + +/* + * match s against p. + * s can be a prefix of p with at least min characters. + */ +int +str_match(s, p, min) + char *s, *p; + int min; +{ + for (; *s && *p && *s == *p; s++, p++, min--) + ; + return *s == *p || (*s == 0 && min <= 0); +} + +#ifdef STR_DEBUG +char * +str_alloc(l) + size_t l; +{ + struct string *s; + + s = (struct string *) malloc(l + str_offset); + if (s == 0) + return 0; + if (str_head.s_forw == 0) + str_head.s_forw = str_head.s_back = &str_head; + s->s_forw = str_head.s_forw; + s->s_back = &str_head; + str_head.s_forw = s; + s->s_forw->s_back = s; + return s->s_data; +} + +void +str_free(str) + char *str; +{ + struct string *s; + + for (s = str_head.s_forw; s != &str_head && s->s_data != str; + s = s->s_forw) + ; + if (s == &str_head) + abort(); + s->s_back->s_forw = s->s_forw; + s->s_forw->s_back = s->s_back; + free((char *)s); +} +#endif diff --git a/window/token.h b/window/token.h new file mode 100644 index 0000000..aa00223 --- /dev/null +++ b/window/token.h @@ -0,0 +1,85 @@ +/* $NetBSD: token.h,v 1.3 1995/09/28 10:34:41 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)token.h 8.1 (Berkeley) 6/6/93 + */ + +#define token (cx.x_token) +#define token_num (cx.x_val.v_num) +#define token_str (cx.x_val.v_str) + +#define T_EOL 1 +#define T_EOF 2 +#define T_COMP 3 +#define T_PLUS 4 +#define T_MINUS 5 +#define T_MUL 6 +#define T_DIV 7 +#define T_LP 8 +#define T_RP 9 +#define T_LB 10 +#define T_RB 11 +#define T_DOLLAR 12 +#define T_COMMA 13 +#define T_QUEST 14 +#define T_COLON 15 +#define T_CHAR 16 +#define T_STR 17 +#define T_NUM 18 +#define T_MOD 19 +#define T_XOR 20 +#define T_DQ 21 /* $? */ +#define T_GE 22 +#define T_RS 23 +#define T_GT 24 +#define T_LE 25 +#define T_LS 26 +#define T_LT 27 +#define T_EQ 28 +#define T_ASSIGN 29 +#define T_NE 30 +#define T_NOT 31 +#define T_ANDAND 32 +#define T_AND 33 +#define T_OROR 34 +#define T_OR 35 + +#define T_IF 40 +#define T_THEN 41 +#define T_ELSIF 42 +#define T_ELSE 43 +#define T_ENDIF 44 diff --git a/window/tt.h b/window/tt.h new file mode 100644 index 0000000..494127d --- /dev/null +++ b/window/tt.h @@ -0,0 +1,183 @@ +/* $NetBSD: tt.h,v 1.4 1997/11/21 08:36:24 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)tt.h 8.1 (Berkeley) 6/6/93 + */ + +#include + +#ifndef EXTERN +#define EXTERN extern +#endif + +/* + * Interface structure for the terminal drivers. + */ +struct tt { + /* startup and cleanup */ + void (*tt_start) __P((void)); + void (*tt_reset) __P((void)); + void (*tt_end) __P((void)); + + /* terminal functions */ + void (*tt_move) __P((int, int)); + void (*tt_insline) __P((int)); + void (*tt_delline) __P((int)); + void (*tt_inschar) __P((char)); + void (*tt_insspace) __P((int)); + void (*tt_delchar) __P((int)); + void (*tt_write) __P((char *, int)); /* write a whole block */ + void (*tt_putc) __P((char)); /* write one character */ + void (*tt_clreol) __P((void)); + void (*tt_clreos) __P((void)); + void (*tt_clear) __P((void)); + void (*tt_scroll_down) __P((int)); + void (*tt_scroll_up) __P((int)); + void (*tt_setscroll) __P((int, int));/* set scrolling region */ + void (*tt_setmodes) __P((int)); /* set display modes */ + void (*tt_set_token) __P((int, char *, int)); + /* define a token */ + void (*tt_put_token) __P((int, char *, int)); + /* refer to a defined token */ + void (*tt_compress) __P((int)); /* begin, end compression */ + void (*tt_checksum) __P((char *, int)); + /* compute checksum */ + void (*tt_checkpoint) __P((void)); /* checkpoint protocol */ + int (*tt_rint) __P((char *, int)); /* input processing */ + + /* internal variables */ + char tt_modes; /* the current display modes */ + char tt_nmodes; /* the new modes for next write */ + char tt_insert; /* currently in insert mode */ + int tt_row; /* cursor row */ + int tt_col; /* cursor column */ + int tt_scroll_top; /* top of scrolling region */ + int tt_scroll_bot; /* bottom of scrolling region */ + + /* terminal info */ + int tt_nrow; /* number of display rows */ + int tt_ncol; /* number of display columns */ + char tt_availmodes; /* the display modes supported */ + char tt_wrap; /* has auto wrap around */ + char tt_retain; /* can retain below (db flag) */ + short tt_padc; /* the pad character */ + int tt_ntoken; /* number of compression tokens */ + int tt_token_min; /* minimun token size */ + int tt_token_max; /* maximum token size */ + int tt_set_token_cost; /* cost in addition to string */ + int tt_put_token_cost; /* constant cost */ + int tt_ack; /* checkpoint ack-nack flag */ + + /* the frame characters */ + short *tt_frame; + + /* ttflush() hook */ + void (*tt_flush) __P((void)); +}; +EXTERN struct tt tt; + +/* + * tt_padc is used by the compression routine. + * It is a short to allow the driver to indicate that there is no padding. + */ +#define TT_PADC_NONE 0x100 + +/* + * List of terminal drivers. + */ +struct tt_tab { + char *tt_name; + int tt_len; + int (*tt_func) __P((void)); +}; +EXTERN struct tt_tab tt_tab[]; + +/* + * Clean interface to termcap routines. + * Too may t's. + */ +EXTERN char tt_strings[1024]; /* string buffer */ +EXTERN char *tt_strp; /* pointer for it */ + +struct tt_str { + char *ts_str; + int ts_n; +}; + +struct tt_str *tttgetstr __P((char *)); +struct tt_str *ttxgetstr __P((char *)); /* tgetstr() and expand delays */ + +int tt_f100 __P((void)); +int tt_generic __P((void)); +int tt_h19 __P((void)); +int tt_h29 __P((void)); +int tt_tvi925 __P((void)); +int tt_wyse60 __P((void)); +int tt_wyse75 __P((void)); +int tt_zapple __P((void)); +int tt_zentec __P((void)); +void ttflush __P((void)); +struct tt_str *tttgetstr __P((char *)); +int ttinit __P((void)); +void ttpgoto __P((struct tt_str *, int, int, int)); +void ttputs __P((char *)); +int ttstrcmp __P((struct tt_str *, struct tt_str *)); +void tttgoto __P((struct tt_str *, int, int)); +void tttputc __P((int)); +void ttwrite __P((char *, int)); +void ttxputc __P((int)); + +#define tttputs(s, n) tputs((s)->ts_str, (n), tttputc) +#define ttxputs(s) ttwrite((s)->ts_str, (s)->ts_n) + +/* + * Buffered output without stdio. + * These variables have different meanings from the ww_ob* variables. + * But I'm too lazy to think up different names. + */ +EXTERN char *tt_ob; +EXTERN char *tt_obp; +EXTERN char *tt_obe; +#define ttputc(c) (tt_obp < tt_obe ? (*tt_obp++ = (c)) \ + : (ttflush(), *tt_obp++ = (c))) + +/* + * Convenience macros for the drivers + * They require char.h + */ +#define ttctrl(c) ttputc(ctrl(c)) +#define ttesc(c) (ttctrl('['), ttputc(c)) diff --git a/window/ttf100.c b/window/ttf100.c new file mode 100644 index 0000000..b59c57a --- /dev/null +++ b/window/ttf100.c @@ -0,0 +1,77 @@ +/* $NetBSD: ttf100.c,v 1.4 1997/11/21 08:36:27 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttf100.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttf100.c,v 1.4 1997/11/21 08:36:27 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Freedom 100 + */ + +#define G (WWM_GRP << WWC_MSHIFT) +short f100_frame[16] = { + ' ', 'J'|G, 'K'|G, 'A'|G, + 'J'|G, 'J'|G, 'B'|G, 'M'|G, + 'K'|G, 'D'|G, 'K'|G, 'O'|G, + 'C'|G, 'L'|G, 'N'|G, 'I'|G +}; +extern struct tt_str *gen_AE, *gen_AS; + +int +tt_f100() +{ + static struct tt_str ae = { "\033%", 2 }; + static struct tt_str as = { "\033$", 2 }; + + if (tt_generic() < 0) + return -1; + tt.tt_frame = f100_frame; + tt.tt_availmodes |= WWM_GRP; + gen_AS = &as; + gen_AE = &ae; + return 0; +} diff --git a/window/ttgeneric.c b/window/ttgeneric.c new file mode 100644 index 0000000..e45224e --- /dev/null +++ b/window/ttgeneric.c @@ -0,0 +1,615 @@ +/* $NetBSD: ttgeneric.c,v 1.5 1998/08/25 20:59:43 ross Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttgeneric.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttgeneric.c,v 1.5 1998/08/25 20:59:43 ross Exp $"); +#endif +#endif /* not lint */ + +#include +#ifdef __APPLE__ +#define _CURSES_PRIVATE +#include +#undef _CURSES_PRIVATE +#else +#include +#endif +#define EXTERN +#include "tt.h" +#undef EXTERN +#include "ww.h" + +extern char PC, *BC, *UP; +extern short ospeed; + + /* normal frame */ +short gen_frame[16] = { + ' ', '|', '-', '+', + '|', '|', '+', '+', + '-', '+', '-', '+', + '+', '+', '+', '+' +}; + + /* ANSI graphics frame */ +#define G (WWM_GRP << WWC_MSHIFT) +short ansi_frame[16] = { + ' ', 'x'|G, 'Q'|G, 'm'|G, + 'x'|G, 'x'|G, 'l'|G, 't'|G, + 'q'|G, 'j'|G, 'q'|G, 'v'|G, + 'k'|G, 'u'|G, 'w'|G, 'n'|G +}; +struct tt_str ansi_AS = { + "\033(0", 3 +}; + +struct tt_str *gen_PC; +struct tt_str *gen_CM; +struct tt_str *gen_IM; +struct tt_str *gen_IC; +struct tt_str *gen_ICn; +struct tt_str *gen_IP; +struct tt_str *gen_EI; +struct tt_str *gen_DC; +struct tt_str *gen_DCn; +struct tt_str *gen_AL; +struct tt_str *gen_ALn; +struct tt_str *gen_DL; +struct tt_str *gen_DLn; +struct tt_str *gen_CE; +struct tt_str *gen_CD; +struct tt_str *gen_CL; +struct tt_str *gen_VS; +struct tt_str *gen_VE; +struct tt_str *gen_TI; +struct tt_str *gen_TE; +struct tt_str *gen_SO; +struct tt_str *gen_SE; +struct tt_str *gen_US; +struct tt_str *gen_UE; +struct tt_str *gen_LE; +struct tt_str *gen_ND; +struct tt_str *gen_UP; +struct tt_str *gen_DO; +struct tt_str *gen_BC; +struct tt_str *gen_NL; +struct tt_str *gen_CR; +struct tt_str *gen_HO; +struct tt_str *gen_AS; +struct tt_str *gen_AE; +struct tt_str *gen_XS; +struct tt_str *gen_XE; +struct tt_str *gen_SF; +struct tt_str *gen_SFn; +struct tt_str *gen_SR; +struct tt_str *gen_SRn; +struct tt_str *gen_CS; +char gen_MI; +char gen_MS; +char gen_AM; +char gen_OS; +char gen_BS; +char gen_DA; +char gen_DB; +char gen_NS; +char gen_XN; +int gen_CO; +int gen_LI; +int gen_UG; +int gen_SG; + +void gen_clear __P((void)); +void gen_clreol __P((void)); +void gen_clreos __P((void)); +void gen_delchar __P((int)); +void gen_delline __P((int)); +void gen_end __P((void)); +void gen_inschar __P((char)); +void gen_insline __P((int)); +void gen_insspace __P((int)); +void gen_move __P((int, int)); +void gen_putc __P((char)); +void gen_scroll_down __P((int)); +void gen_scroll_up __P((int)); +void gen_setinsert __P((char)); +void gen_setmodes __P((int)); +void gen_setscroll __P((int, int)); +void gen_start __P((void)); +void gen_write __P((char *, int)); + +void +gen_setinsert(new) + char new; +{ + if (new) { + if (gen_IM) + ttxputs(gen_IM); + } else + if (gen_EI) + ttxputs(gen_EI); + tt.tt_insert = new; +} + +void +gen_setmodes(new) + int new; +{ + int diff; + + diff = new ^ tt.tt_modes; + if (diff & WWM_REV) { + if (new & WWM_REV) { + if (gen_SO) + ttxputs(gen_SO); + } else + if (gen_SE) + ttxputs(gen_SE); + } + if (diff & WWM_UL) { + if (new & WWM_UL) { + if (gen_US) + ttxputs(gen_US); + } else + if (gen_UE) + ttxputs(gen_UE); + } + if (diff & WWM_GRP) { + if (new & WWM_GRP) { + if (gen_AS) + ttxputs(gen_AS); + } else + if (gen_AE) + ttxputs(gen_AE); + } + if (diff & WWM_USR) { + if (new & WWM_USR) { + if (gen_XS) + ttxputs(gen_XS); + } else + if (gen_XE) + ttxputs(gen_XE); + } + tt.tt_modes = new; +} + +void +gen_insline(n) + int n; +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + if (gen_ALn) + ttpgoto(gen_ALn, 0, n, gen_LI - tt.tt_row); + else + while (--n >= 0) + tttputs(gen_AL, gen_LI - tt.tt_row); +} + +void +gen_delline(n) + int n; +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + if (gen_DLn) + ttpgoto(gen_DLn, 0, n, gen_LI - tt.tt_row); + else + while (--n >= 0) + tttputs(gen_DL, gen_LI - tt.tt_row); +} + +void +gen_putc(c) + char c; +{ + if (tt.tt_insert) + gen_setinsert(0); + if (tt.tt_nmodes != tt.tt_modes) + gen_setmodes(tt.tt_nmodes); + ttputc(c); + if (++tt.tt_col == gen_CO) { + if (gen_XN) + tt.tt_col = tt.tt_row = -10; + else if (gen_AM) + tt.tt_col = 0, tt.tt_row++; + else + tt.tt_col--; + } +} + +void +gen_write(p, n) + char *p; + int n; +{ + if (tt.tt_insert) + gen_setinsert(0); + if (tt.tt_nmodes != tt.tt_modes) + gen_setmodes(tt.tt_nmodes); + ttwrite(p, n); + tt.tt_col += n; + if (tt.tt_col == gen_CO) { + if (gen_XN) + tt.tt_col = tt.tt_row = -10; + else if (gen_AM) + tt.tt_col = 0, tt.tt_row++; + else + tt.tt_col--; + } +} + +void +gen_move(row, col) + int row, col; +{ + if (tt.tt_row == row && tt.tt_col == col) + return; + if (!gen_MI && tt.tt_insert) + gen_setinsert(0); + if (!gen_MS && tt.tt_modes) + gen_setmodes(0); + if (row < tt.tt_scroll_top || row > tt.tt_scroll_bot) + gen_setscroll(0, tt.tt_nrow - 1); + if (tt.tt_row == row) { + if (col == 0) { + ttxputs(gen_CR); + goto out; + } + if (tt.tt_col == col - 1) { + if (gen_ND) { + ttxputs(gen_ND); + goto out; + } + } else if (tt.tt_col == col + 1) { + if (gen_LE) { + ttxputs(gen_LE); + goto out; + } + } + } + if (tt.tt_col == col) { + if (tt.tt_row == row + 1) { + if (gen_UP) { + ttxputs(gen_UP); + goto out; + } + } else if (tt.tt_row == row - 1) { + ttxputs(gen_DO); + goto out; + } + } + if (gen_HO && col == 0 && row == 0) { + ttxputs(gen_HO); + goto out; + } + tttgoto(gen_CM, col, row); +out: + tt.tt_col = col; + tt.tt_row = row; +} + +void +gen_start() +{ + if (gen_VS) + ttxputs(gen_VS); + if (gen_TI) + ttxputs(gen_TI); + ttxputs(gen_CL); + tt.tt_col = tt.tt_row = 0; + tt.tt_insert = 0; + tt.tt_nmodes = tt.tt_modes = 0; +} + +void +gen_end() +{ + if (tt.tt_insert) + gen_setinsert(0); + if (gen_TE) + ttxputs(gen_TE); + if (gen_VE) + ttxputs(gen_VE); +} + +void +gen_clreol() +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + tttputs(gen_CE, gen_CO - tt.tt_col); +} + +void +gen_clreos() +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + tttputs(gen_CD, gen_LI - tt.tt_row); +} + +void +gen_clear() +{ + if (tt.tt_modes) /* for concept 100 */ + gen_setmodes(0); + ttxputs(gen_CL); +} + +void +gen_inschar(c) + char c; +{ + if (!tt.tt_insert) + gen_setinsert(1); + if (tt.tt_nmodes != tt.tt_modes) + gen_setmodes(tt.tt_nmodes); + if (gen_IC) + tttputs(gen_IC, gen_CO - tt.tt_col); + ttputc(c); + if (gen_IP) + tttputs(gen_IP, gen_CO - tt.tt_col); + if (++tt.tt_col == gen_CO) { + if (gen_XN) + tt.tt_col = tt.tt_row = -10; + else if (gen_AM) + tt.tt_col = 0, tt.tt_row++; + else + tt.tt_col--; + } +} + +void +gen_insspace(n) + int n; +{ + if (gen_ICn) + ttpgoto(gen_ICn, 0, n, gen_CO - tt.tt_col); + else + while (--n >= 0) + tttputs(gen_IC, gen_CO - tt.tt_col); +} + +void +gen_delchar(n) + int n; +{ + if (gen_DCn) + ttpgoto(gen_DCn, 0, n, gen_CO - tt.tt_col); + else + while (--n >= 0) + tttputs(gen_DC, gen_CO - tt.tt_col); +} + +void +gen_scroll_down(n) + int n; +{ + gen_move(tt.tt_scroll_bot, 0); + if (gen_SFn) + ttpgoto(gen_SFn, 0, n, n); + else + while (--n >= 0) + ttxputs(gen_SF); +} + +void +gen_scroll_up(n) + int n; +{ + gen_move(tt.tt_scroll_top, 0); + if (gen_SRn) + ttpgoto(gen_SRn, 0, n, n); + else + while (--n >= 0) + ttxputs(gen_SR); +} + +void +gen_setscroll(top, bot) + int top, bot; +{ + tttgoto(gen_CS, bot, top); + tt.tt_scroll_top = top; + tt.tt_scroll_bot = bot; + tt.tt_row = tt.tt_col = -10; +} + +int +tt_generic() +{ + gen_PC = tttgetstr("pc"); + PC = gen_PC ? *gen_PC->ts_str : 0; + ospeed = wwospeed; + + gen_CM = ttxgetstr("cm"); /* may not work */ + gen_IM = ttxgetstr("im"); + gen_IC = tttgetstr("ic"); + gen_ICn = tttgetstr("IC"); + gen_IP = tttgetstr("ip"); + gen_EI = ttxgetstr("ei"); + gen_DC = tttgetstr("dc"); + gen_DCn = tttgetstr("DC"); + gen_AL = tttgetstr("al"); + gen_ALn = tttgetstr("AL"); + gen_DL = tttgetstr("dl"); + gen_DLn = tttgetstr("DL"); + gen_CE = tttgetstr("ce"); + gen_CD = tttgetstr("cd"); + gen_CL = ttxgetstr("cl"); + gen_VS = ttxgetstr("vs"); + gen_VE = ttxgetstr("ve"); + gen_TI = ttxgetstr("ti"); + gen_TE = ttxgetstr("te"); + gen_SO = ttxgetstr("so"); + gen_SE = ttxgetstr("se"); + gen_US = ttxgetstr("us"); + gen_UE = ttxgetstr("ue"); + gen_LE = ttxgetstr("le"); + gen_ND = ttxgetstr("nd"); + gen_UP = ttxgetstr("up"); + gen_DO = ttxgetstr("do"); + gen_BC = ttxgetstr("bc"); + gen_NL = ttxgetstr("nl"); + gen_CR = ttxgetstr("cr"); + gen_HO = ttxgetstr("ho"); + gen_AS = ttxgetstr("as"); + gen_AE = ttxgetstr("ae"); + gen_XS = ttxgetstr("XS"); + gen_XE = ttxgetstr("XE"); + gen_SF = ttxgetstr("sf"); + gen_SFn = ttxgetstr("SF"); + gen_SR = ttxgetstr("sr"); + gen_SRn = ttxgetstr("SR"); + gen_CS = ttxgetstr("cs"); + gen_MI = tgetflag("mi"); + gen_MS = tgetflag("ms"); + gen_AM = tgetflag("am"); + gen_OS = tgetflag("os"); + gen_BS = tgetflag("bs"); + gen_DA = tgetflag("da"); + gen_DB = tgetflag("db"); + gen_NS = tgetflag("ns"); + gen_XN = tgetflag("xn"); + gen_CO = tgetnum("co"); + gen_LI = tgetnum("li"); + gen_UG = tgetnum("ug"); + gen_SG = tgetnum("sg"); + if (gen_CL == 0 || gen_OS || gen_CM == 0) + return -1; + + /* + * Deal with obsolete termcap fields. + */ + if (gen_LE == 0) { + if (gen_BC) + gen_LE = gen_BC; + else if (gen_BS) { + static struct tt_str bc = { "\b", 1 }; + gen_BC = &bc; + } + } + if (gen_NL == 0) { + static struct tt_str nl = { "\n", 1 }; + gen_NL = &nl; + } + if (gen_DO == 0) + gen_DO = gen_NL; + if (gen_CR == 0) { + static struct tt_str cr = { "\r", 1 }; + gen_CR = &cr; + } + /* + * Most terminal will scroll with "nl", but very few specify "sf". + * We shouldn't use "do" here. + */ + if (gen_SF == 0 && !gen_NS) + gen_SF = gen_NL; + BC = gen_LE ? gen_LE->ts_str : 0; + UP = gen_UP ? gen_UP->ts_str : 0; + /* + * Fix up display attributes that we can't handle, or don't + * really exist. + */ + if (gen_SG > 0) + gen_SO = 0; + if (gen_UG > 0 || (gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0)) + gen_US = 0; + + if (gen_IM && gen_IM->ts_n == 0) { + free((char *) gen_IM); + gen_IM = 0; + } + if (gen_EI && gen_EI->ts_n == 0) { + free((char *) gen_EI); + gen_EI = 0; + } + if (gen_IC && gen_IC->ts_n == 0) { + free((char *) gen_IC); + gen_IC = 0; + } + if (gen_IM) + tt.tt_inschar = gen_inschar; + else if (gen_IC) + tt.tt_insspace = gen_insspace; + if (gen_DC) + tt.tt_delchar = gen_delchar; + if (gen_AL) + tt.tt_insline = gen_insline; + if (gen_DL) + tt.tt_delline = gen_delline; + if (gen_CE) + tt.tt_clreol = gen_clreol; + if (gen_CD) + tt.tt_clreos = gen_clreos; + if (gen_SF) + tt.tt_scroll_down = gen_scroll_down; + /* + * Don't allow scroll_up if da or db but not cs. + * See comment in wwscroll.c. + */ + if (gen_SR && (gen_CS || (!gen_DA && !gen_DB))) + tt.tt_scroll_up = gen_scroll_up; + if (gen_CS) + tt.tt_setscroll = gen_setscroll; + if (gen_SO) + tt.tt_availmodes |= WWM_REV; + if (gen_US) + tt.tt_availmodes |= WWM_UL; + if (gen_AS) + tt.tt_availmodes |= WWM_GRP; + if (gen_XS) + tt.tt_availmodes |= WWM_USR; + tt.tt_wrap = gen_AM; + tt.tt_retain = gen_DB; + tt.tt_ncol = gen_CO; + tt.tt_nrow = gen_LI; + tt.tt_start = gen_start; + tt.tt_end = gen_end; + tt.tt_write = gen_write; + tt.tt_putc = gen_putc; + tt.tt_move = gen_move; + tt.tt_clear = gen_clear; + tt.tt_setmodes = gen_setmodes; + tt.tt_frame = gen_AS && ttstrcmp(gen_AS, &ansi_AS) == 0 ? + ansi_frame : gen_frame; + return 0; +} diff --git a/window/tth19.c b/window/tth19.c new file mode 100644 index 0000000..fa16b68 --- /dev/null +++ b/window/tth19.c @@ -0,0 +1,322 @@ +/* $NetBSD: tth19.c,v 1.4 1997/11/21 08:36:30 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tth19.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: tth19.c,v 1.4 1997/11/21 08:36:30 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* +kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith: + cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK: + cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB: + ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms: + ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4: + kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH: + kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW: + l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER: + es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1: +*/ + +#define NCOL 80 +#define NROW 24 + +#define G (WWM_GRP << WWC_MSHIFT) +short h19_frame[16] = { + ' ', '`'|G, 'a'|G, 'e'|G, + '`'|G, '`'|G, 'f'|G, 'v'|G, + 'a'|G, 'd'|G, 'a'|G, 'u'|G, + 'c'|G, 't'|G, 's'|G, 'b'|G +}; + +extern struct tt_str *gen_VS; +extern struct tt_str *gen_VE; + +int h19_msp10c; + +#define PAD(ms10) { \ + int i; \ + for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \ + ttputc('\0'); \ +} +#define ICPAD() PAD((NCOL - tt.tt_col) * 1) /* 0.1 ms per char */ +#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */ + +#define H19_SETINSERT(m) ttesc((tt.tt_insert = (m)) ? '@' : 'O') + +void h19_clear __P((void)); +void h19_clreol __P((void)); +void h19_clreos __P((void)); +void h19_delchar __P((int)); +void h19_delline __P((int)); +void h19_end __P((void)); +void h19_inschar __P((char)); +void h19_insline __P((int)); +void h19_move __P((int, int)); +void h19_putc __P((char)); +void h19_scroll_up __P((int)); +void h19_scroll_down __P((int)); +void h19_setmodes __P((int)); +void h19_start __P((void)); +void h19_write __P((char *, int)); + +void +h19_setmodes(new) + int new; +{ + int diff; + + diff = new ^ tt.tt_modes; + if (diff & WWM_REV) + ttesc(new & WWM_REV ? 'p' : 'q'); + if (diff & WWM_GRP) + ttesc(new & WWM_REV ? 'F' : 'G'); + tt.tt_modes = new; +} + +void +h19_insline(n) + int n; +{ + while (--n >= 0) { + ttesc('L'); + ILPAD(); + } +} + +void +h19_delline(n) + int n; +{ + while (--n >= 0) { + ttesc('M'); + ILPAD(); + } +} + +void +h19_putc(c) + char c; +{ + if (tt.tt_nmodes != tt.tt_modes) + (*tt.tt_setmodes)(tt.tt_nmodes); + if (tt.tt_insert) + H19_SETINSERT(0); + ttputc(c); + if (++tt.tt_col == NCOL) + tt.tt_col = NCOL - 1; +} + +void +h19_write(p, n) + char *p; + int n; +{ + if (tt.tt_nmodes != tt.tt_modes) + (*tt.tt_setmodes)(tt.tt_nmodes); + if (tt.tt_insert) + H19_SETINSERT(0); + ttwrite(p, n); + tt.tt_col += n; + if (tt.tt_col == NCOL) + tt.tt_col = NCOL - 1; +} + +void +h19_move(row, col) + int row, col; +{ + if (tt.tt_row == row) { + if (tt.tt_col == col) + return; + if (col == 0) { + ttctrl('m'); + goto out; + } + if (tt.tt_col == col - 1) { + ttesc('C'); + goto out; + } + if (tt.tt_col == col + 1) { + ttctrl('h'); + goto out; + } + } + if (tt.tt_col == col) { + if (tt.tt_row == row + 1) { + ttesc('A'); + goto out; + } + if (tt.tt_row == row - 1) { + ttctrl('j'); + goto out; + } + } + if (col == 0 && row == 0) { + ttesc('H'); + goto out; + } + ttesc('Y'); + ttputc(' ' + row); + ttputc(' ' + col); +out: + tt.tt_col = col; + tt.tt_row = row; +} + +void +h19_start() +{ + if (gen_VS) + ttxputs(gen_VS); + ttesc('w'); + ttesc('E'); + tt.tt_col = tt.tt_row = 0; + tt.tt_insert = 0; + tt.tt_nmodes = tt.tt_modes = 0; +} + +void +h19_end() +{ + if (tt.tt_insert) + H19_SETINSERT(0); + if (gen_VE) + ttxputs(gen_VE); + ttesc('v'); +} + +void +h19_clreol() +{ + ttesc('K'); +} + +void +h19_clreos() +{ + ttesc('J'); +} + +void +h19_clear() +{ + ttesc('E'); +} + +void +h19_inschar(c) + char c; +{ + if (tt.tt_nmodes != tt.tt_modes) + (*tt.tt_setmodes)(tt.tt_nmodes); + if (!tt.tt_insert) + H19_SETINSERT(1); + ttputc(c); + if (tt.tt_insert) + ICPAD(); + if (++tt.tt_col == NCOL) + tt.tt_col = NCOL - 1; +} + +void +h19_delchar(n) + int n; +{ + while (--n >= 0) + ttesc('N'); +} + +void +h19_scroll_down(n) + int n; +{ + h19_move(NROW - 1, 0); + while (--n >= 0) + ttctrl('j'); +} + +void +h19_scroll_up(n) + int n; +{ + h19_move(0, 0); + while (--n >= 0) + ttesc('I'); +} + +int +tt_h19() +{ + float cpms = (float) wwbaud / 10000; /* char per ms */ + + h19_msp10c = 10 / cpms; /* ms per 10 char */ + gen_VS = ttxgetstr("vs"); + gen_VE = ttxgetstr("ve"); + + tt.tt_start = h19_start; + tt.tt_end = h19_end; + + tt.tt_insline = h19_insline; + tt.tt_delline = h19_delline; + tt.tt_inschar = h19_inschar; + tt.tt_delchar = h19_delchar; + tt.tt_clreol = h19_clreol; + tt.tt_clreos = h19_clreos; + tt.tt_clear = h19_clear; + tt.tt_move = h19_move; + tt.tt_write = h19_write; + tt.tt_putc = h19_putc; + tt.tt_scroll_down = h19_scroll_down; + tt.tt_scroll_up = h19_scroll_up; + tt.tt_setmodes = h19_setmodes; + + tt.tt_ncol = NCOL; + tt.tt_nrow = NROW; + tt.tt_availmodes = WWM_REV|WWM_GRP; + tt.tt_frame = h19_frame; + return 0; +} diff --git a/window/tth29.c b/window/tth29.c new file mode 100644 index 0000000..0375cfb --- /dev/null +++ b/window/tth29.c @@ -0,0 +1,105 @@ +/* $NetBSD: tth29.c,v 1.4 1997/11/21 08:36:31 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tth29.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: tth29.c,v 1.4 1997/11/21 08:36:31 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* + * H29 Driver + * + * WWM_USR mode is alternate character set. + * +kC|h29|heath-29|z29|zenith-29:\ + :am:bc=\ED:bt=\E-:cr=^M:do=^J:nl=^J:bl=^G:\ + :al=\EL:le=^H:bs:cd=\EJ:ce=\EK:cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:\ + :dl=1*\EM:do=\EB:ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:\ + :ms:ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:\ + :kb=^H:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:kn#1:k0=\E~:l0=HOME:\ + :k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:k6=\EP:k7=\EQ:k8=\ER:k9=\E01:\ + :es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:us=\Es8:ue=\Es0: + * + */ + +void h29_setmodes __P((int)); + +void +h29_setmodes(new) + int new; +{ + int modes = '0'; + + if (new & WWM_REV) + modes += 0x01; + if (new & WWM_BLK) + modes += 0x02; + if (new & WWM_DIM) + modes += 0x04; + if (new & WWM_UL) + modes += 0x08; + if (new & WWM_USR) + modes += 0x10; + ttesc('s'); + ttputc(modes); + if (new & WWM_GRP) { + if ((tt.tt_modes & WWM_GRP) == 0) + ttesc('F'); + } else + if (tt.tt_modes & WWM_GRP) + ttesc('G'); + tt.tt_modes = new; +} + +int +tt_h29() +{ + if (tt_h19() < 0) + return -1; + tt.tt_setmodes = h29_setmodes; + tt.tt_availmodes |= WWM_BLK|WWM_UL|WWM_DIM|WWM_USR; + return 0; +} diff --git a/window/ttinit.c b/window/ttinit.c new file mode 100644 index 0000000..f9e2d42 --- /dev/null +++ b/window/ttinit.c @@ -0,0 +1,120 @@ +/* $NetBSD: ttinit.c,v 1.4 1997/11/21 08:36:32 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttinit.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttinit.c,v 1.4 1997/11/21 08:36:32 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "ww.h" +#include "tt.h" + +struct tt_tab tt_tab[] = { + { "h19", 3, tt_h19 }, + { "h29", 3, tt_h29 }, + { "f100", 4, tt_f100 }, + { "tvi925", 6, tt_tvi925 }, + { "wyse75", 6, tt_wyse75 }, + { "wyse60", 6, tt_wyse60 }, + { "w60", 3, tt_wyse60 }, + { "zapple", 6, tt_zapple }, + { "zentec", 6, tt_zentec }, + { "generic", 0, tt_generic }, + { 0, 0, 0 } +}; + +int +ttinit() +{ + int i; + struct tt_tab *tp; + char *p, *q; + char *t; + + tt_strp = tt_strings; + + /* + * Set output buffer size to about 1 second of output time. + */ + i = MIN(wwbaud/10, 512); + if ((tt_ob = malloc((unsigned) i)) == 0) { + wwerrno = WWE_NOMEM; + return -1; + } + tt_obp = tt_ob; + tt_obe = tt_ob + i; + + /* + * Use the standard name of the terminal (i.e. the second + * name in termcap). + */ + for (p = wwtermcap; *p && *p != '|' && *p != ':'; p++) + ; + if (*p == '|') + p++; + for (q = p; *q && *q != '|' && *q != ':'; q++) + ; + if (q != p && (t = malloc((unsigned) (q - p + 1))) != 0) { + wwterm = t; + while (p < q) + *t++ = *p++; + *t = 0; + } + for (tp = tt_tab; tp->tt_name != 0; tp++) + if (strncmp(tp->tt_name, wwterm, tp->tt_len) == 0) + break; + if (tp->tt_name == 0) { + wwerrno = WWE_BADTERM; + return -1; + } + if ((*tp->tt_func)() < 0) { + wwerrno = WWE_CANTDO; + return -1; + } + if (wwgetttysize(0, &tt.tt_nrow, &tt.tt_ncol) < 0) + return -1; + tt.tt_scroll_top = 0; + tt.tt_scroll_bot = tt.tt_nrow - 1; + return 0; +} diff --git a/window/ttoutput.c b/window/ttoutput.c new file mode 100644 index 0000000..66cdae2 --- /dev/null +++ b/window/ttoutput.c @@ -0,0 +1,157 @@ +/* $NetBSD: ttoutput.c,v 1.4 1997/11/21 08:36:34 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttoutput.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttoutput.c,v 1.4 1997/11/21 08:36:34 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include "ww.h" +#include "tt.h" + +/* + * Buffered output package. + * We need this because stdio fails on non-blocking writes. + */ + +void +ttflush() +{ + char *p; + int n = tt_obp - tt_ob; + + if (n == 0) + return; + if (tt.tt_checksum) + (*tt.tt_checksum)(tt_ob, n); + if (tt.tt_flush) { + (*tt.tt_flush)(); + return; + } + wwnflush++; + for (p = tt_ob; p < tt_obp;) { + wwnwr++; + n = write(1, p, tt_obp - p); + if (n < 0) { + wwnwre++; + if (errno != EWOULDBLOCK) { + /* can't deal with this */ + p = tt_obp; + } + } else if (n == 0) { + /* what to do? */ + wwnwrz++; + } else { + wwnwrc += n; + p += n; + } + } + tt_obp = tt_ob; +} + +void +ttputs(s) + char *s; +{ + while (*s) + ttputc(*s++); +} + +void +ttwrite(s, n) + char *s; + int n; +{ + switch (n) { + case 0: + break; + case 1: + ttputc(*s); + break; + case 2: + if (tt_obe - tt_obp < 2) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + case 3: + if (tt_obe - tt_obp < 3) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + case 4: + if (tt_obe - tt_obp < 4) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + case 5: + if (tt_obe - tt_obp < 5) + ttflush(); + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s++; + *tt_obp++ = *s; + break; + default: + while (n > 0) { + int m; + + while ((m = tt_obe - tt_obp) == 0) + ttflush(); + if ((m = tt_obe - tt_obp) > n) + m = n; + memmove(tt_obp, s, m); + tt_obp += m; + s += m; + n -= m; + } + } +} diff --git a/window/tttermcap.c b/window/tttermcap.c new file mode 100644 index 0000000..202ce4e --- /dev/null +++ b/window/tttermcap.c @@ -0,0 +1,135 @@ +/* $NetBSD: tttermcap.c,v 1.4 1997/11/21 08:36:35 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tttermcap.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: tttermcap.c,v 1.4 1997/11/21 08:36:35 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#ifdef __APPLE__ +#include +#else +#include +#endif +#include "tt.h" + +void +tttputc(c) + int c; +{ + ttputc(c); +} + +void +ttxputc(c) + int c; +{ + *tt_strp++ = c; +} + +struct tt_str * +tttgetstr(str) + char *str; +{ + struct tt_str *s; + + if ((str = tgetstr(str, &tt_strp)) == 0) + return 0; + if ((s = (struct tt_str *) malloc(sizeof *s)) == 0) + return 0; + s->ts_str = str; + s->ts_n = tt_strp - s->ts_str - 1; + return s; +} + +struct tt_str * +ttxgetstr(str) + char *str; +{ + struct tt_str *s; + char buf[100]; + char *bufp = buf; + + if (tgetstr(str, &bufp) == 0) + return 0; + if ((s = (struct tt_str *) malloc(sizeof *s)) == 0) + return 0; + s->ts_str = tt_strp; + tputs(buf, 1, ttxputc); + s->ts_n = tt_strp - s->ts_str; + *tt_strp++ = 0; + return s; +} + +void +tttgoto(s, col, row) + struct tt_str *s; + int col, row; +{ + char *p = s->ts_str; + + ttputs(tgoto(p, col, row)); + for (p += s->ts_n; *--p == 0;) + ttputc(0); +} + +void +ttpgoto(s, col, row, n) + struct tt_str *s; + int col, row, n; +{ + + tputs(tgoto(s->ts_str, col, row), n, tttputc); +} + +int +ttstrcmp(a, b) + struct tt_str *a, *b; +{ + int n, r; + + if ((r = memcmp(a->ts_str, b->ts_str, + (n = a->ts_n - b->ts_n) < 0 ? a->ts_n : b->ts_n))) + return r; + return n; +} diff --git a/window/tttvi925.c b/window/tttvi925.c new file mode 100644 index 0000000..1818102 --- /dev/null +++ b/window/tttvi925.c @@ -0,0 +1,72 @@ +/* $NetBSD: tttvi925.c,v 1.4 1997/11/21 08:36:37 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * David Barto at Celerity Computer Corp. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)tttvi925.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: tttvi925.c,v 1.4 1997/11/21 08:36:37 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Televideo 925 as emulated by Microterm. + */ + +#define G (WWM_GRP << WWC_MSHIFT) +short tvi925_frame[16] = { + ' ', '~'|G, '|'|G, 'c'|G, + '~'|G, '~'|G, '`'|G, 'e'|G, + '|'|G, 'a'|G, '|'|G, 'g'|G, + 'b'|G, 'f'|G, 'h'|G, 'd'|G +}; + +int +tt_tvi925() +{ + + if (tt_generic() < 0) + return -1; + tt.tt_availmodes |= WWM_GRP; + tt.tt_frame = tvi925_frame; + return 0; +} diff --git a/window/ttwyse60.c b/window/ttwyse60.c new file mode 100644 index 0000000..3bd7f16 --- /dev/null +++ b/window/ttwyse60.c @@ -0,0 +1,84 @@ +/* $NetBSD: ttwyse60.c,v 1.4 1997/11/21 08:36:39 lukem Exp $ */ + +/* + * Copyright 1987 by David C. Elliott, MIPS Computer Systems. + * + * Unlimited redistribution allowed as long as this notice + * is kept intact. + */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * David C. Elliott, of MIPS Computer Systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttwyse60.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttwyse60.c,v 1.4 1997/11/21 08:36:39 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +#define G (WWM_GRP << WWC_MSHIFT) +short wyse60_frame[16] = { + ' ', '6'|G, ':'|G, '1'|G, + '6'|G, '6'|G, '2'|G, '4'|G, + ':'|G, '5'|G, ':'|G, '='|G, + '3'|G, '9'|G, '0'|G, '0'|G +}; + +extern struct tt_str *gen_AS; +extern struct tt_str *gen_AE; + +int +tt_wyse60() +{ + static struct tt_str ae = { "\033H\003", 3 }; + static struct tt_str as = { "\033H\002", 3 }; + + if (tt_generic() < 0) + return -1; + tt.tt_availmodes |= WWM_GRP; + tt.tt_frame = wyse60_frame; + if (gen_AS == 0) + gen_AS = &as; + if (gen_AE == 0) + gen_AE = &ae; + return 0; +} diff --git a/window/ttwyse75.c b/window/ttwyse75.c new file mode 100644 index 0000000..175b215 --- /dev/null +++ b/window/ttwyse75.c @@ -0,0 +1,84 @@ +/* $NetBSD: ttwyse75.c,v 1.4 1997/11/21 08:36:40 lukem Exp $ */ + +/* + * Copyright 1987 by David C. Elliott, MIPS Computer Systems. + * + * Unlimited redistribution allowed as long as this notice + * is kept intact. + */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * David C. Elliott, of MIPS Computer Systems. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttwyse75.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttwyse75.c,v 1.4 1997/11/21 08:36:40 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +#define G (WWM_GRP << WWC_MSHIFT) +short wyse75_frame[16] = { + ' ', 'x'|G, 'q'|G, 'm'|G, + 'x'|G, 'x'|G, 'l'|G, 't'|G, + 'q'|G, 'j'|G, 'q'|G, 'v'|G, + 'k'|G, 'u'|G, 'w'|G, 'v'|G +}; + +extern struct tt_str *gen_AS; +extern struct tt_str *gen_AE; + +int +tt_wyse75() +{ + static struct tt_str ae = { "\033(B", 3 }; + static struct tt_str as = { "\033(0", 3 }; + + if (tt_generic() < 0) + return -1; + tt.tt_availmodes |= WWM_GRP; + tt.tt_frame = wyse75_frame; + if (gen_AS == 0) + gen_AS = &as; + if (gen_AE == 0) + gen_AE = &ae; + return 0; +} diff --git a/window/ttzapple.c b/window/ttzapple.c new file mode 100644 index 0000000..ca0a0f7 --- /dev/null +++ b/window/ttzapple.c @@ -0,0 +1,552 @@ +/* $NetBSD: ttzapple.c,v 1.4 1997/11/21 08:36:42 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttzapple.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttzapple.c,v 1.4 1997/11/21 08:36:42 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* +zz|zapple|perfect apple:\ + :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\ + :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\ + :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\ + :so=\E+:se=\E-:\ + :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\ + :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\ + :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\ + :is=\E-\ET : +*/ + +#define NCOL 80 +#define NROW 24 +#define TOKEN_MAX 32 + +extern short gen_frame[]; + + /* for error correction */ +int zz_ecc; +int zz_lastc; + + /* for checkpointing */ +int zz_sum; + +void zz_checkpoint __P((void)); +void zz_checksum __P((char *, int)); +void zz_clear __P((void)); +void zz_clreol __P((void)); +void zz_clreos __P((void)); +void zz_compress __P((int)); +void zz_delchar __P((int)); +void zz_delline __P((int)); +void zz_end __P((void)); +void zz_insline __P((int)); +void zz_insspace __P((int)); +void zz_move __P((int, int)); +void zz_put_token __P((int, char *, int)); +void zz_putc __P((char)); +void zz_reset __P((void)); +int zz_rint __P((char *, int)); +void zz_scroll_down __P((int)); +void zz_scroll_up __P((int)); +void zz_setmodes __P((int)); +void zz_setscroll __P((int, int)); +void zz_set_token __P((int, char *, int)); +void zz_start __P((void)); +void zz_write __P((char *, int)); + +void +zz_setmodes(new) + int new; +{ + if (new & WWM_REV) { + if ((tt.tt_modes & WWM_REV) == 0) + ttesc('+'); + } else + if (tt.tt_modes & WWM_REV) + ttesc('-'); + tt.tt_modes = new; +} + +void +zz_insline(n) + int n; +{ + if (n == 1) + ttesc('a'); + else { + ttesc('A'); + ttputc(n + ' '); + } +} + +void +zz_delline(n) + int n; +{ + if (n == 1) + ttesc('d'); + else { + ttesc('D'); + ttputc(n + ' '); + } +} + +void +zz_putc(c) + char c; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + ttputc(c); + if (++tt.tt_col == NCOL) + tt.tt_col = 0, tt.tt_row++; +} + +void +zz_write(p, n) + char *p; + int n; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + ttwrite(p, n); + tt.tt_col += n; + if (tt.tt_col == NCOL) + tt.tt_col = 0, tt.tt_row++; +} + +void +zz_move(row, col) + int row, col; +{ + int x; + + if (tt.tt_row == row) { +same_row: + if ((x = col - tt.tt_col) == 0) + return; + if (col == 0) { + ttctrl('m'); + goto out; + } + switch (x) { + case 2: + ttctrl('f'); + case 1: + ttctrl('f'); + goto out; + case -2: + ttctrl('h'); + case -1: + ttctrl('h'); + goto out; + } + if ((col & 7) == 0 && x > 0 && x <= 16) { + ttctrl('i'); + if (x > 8) + ttctrl('i'); + goto out; + } + ttesc('<'); + ttputc(col + ' '); + goto out; + } + if (tt.tt_col == col) { + switch (row - tt.tt_row) { + case 2: + ttctrl('j'); + case 1: + ttctrl('j'); + goto out; + case -2: + ttctrl('k'); + case -1: + ttctrl('k'); + goto out; + } + if (col == 0) { + if (row == 0) + goto home; + if (row == NROW - 1) + goto ll; + } + ttesc('>'); + ttputc(row + ' '); + goto out; + } + if (col == 0) { + if (row == 0) { +home: + ttesc('0'); + goto out; + } + if (row == tt.tt_row + 1) { + /* + * Do newline first to match the sequence + * for scroll down and return + */ + ttctrl('j'); + ttctrl('m'); + goto out; + } + if (row == NROW - 1) { +ll: + ttesc('1'); + goto out; + } + } + /* favor local motion for better compression */ + if (row == tt.tt_row + 1) { + ttctrl('j'); + goto same_row; + } + if (row == tt.tt_row - 1) { + ttctrl('k'); + goto same_row; + } + ttesc('='); + ttputc(' ' + row); + ttputc(' ' + col); +out: + tt.tt_col = col; + tt.tt_row = row; +} + +void +zz_start() +{ + ttesc('T'); + ttputc(TOKEN_MAX + ' '); + ttesc('U'); + ttputc('!'); + zz_ecc = 1; + zz_lastc = -1; + ttesc('v'); + ttflush(); + zz_sum = 0; + zz_setscroll(0, NROW - 1); + zz_clear(); + zz_setmodes(0); +} + +void +zz_reset() +{ + zz_setscroll(0, NROW - 1); + tt.tt_modes = WWM_REV; + zz_setmodes(0); + tt.tt_col = tt.tt_row = -10; +} + +void +zz_end() +{ + ttesc('T'); + ttputc(' '); + ttesc('U'); + ttputc(' '); + zz_ecc = 0; +} + +void +zz_clreol() +{ + ttesc('2'); +} + +void +zz_clreos() +{ + ttesc('3'); +} + +void +zz_clear() +{ + ttesc('4'); + tt.tt_col = tt.tt_row = 0; +} + +void +zz_insspace(n) + int n; +{ + if (n == 1) + ttesc('i'); + else { + ttesc('I'); + ttputc(n + ' '); + } +} + +void +zz_delchar(n) + int n; +{ + if (n == 1) + ttesc('c'); + else { + ttesc('C'); + ttputc(n + ' '); + } +} + +void +zz_scroll_down(n) + int n; +{ + if (n == 1) + if (tt.tt_row == NROW - 1) + ttctrl('j'); + else + ttesc('f'); + else { + ttesc('F'); + ttputc(n + ' '); + } +} + +void +zz_scroll_up(n) + int n; +{ + if (n == 1) + ttesc('r'); + else { + ttesc('R'); + ttputc(n + ' '); + } +} + +void +zz_setscroll(top, bot) + int top, bot; +{ + ttesc('?'); + ttputc(top + ' '); + ttputc(bot + ' '); + tt.tt_scroll_top = top; + tt.tt_scroll_bot = bot; +} + +int zz_debug = 0; + +void +zz_set_token(t, s, n) + int t; + char *s; + int n; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + if (zz_debug) { + char buf[100]; + zz_setmodes(WWM_REV); + (void) sprintf(buf, "%02x=", t); + ttputs(buf); + tt.tt_col += 3; + } + ttputc(0x80); + ttputc(t + 1); + s[n - 1] |= 0x80; + ttwrite(s, n); + s[n - 1] &= ~0x80; +} + +void +zz_put_token(t, s, n) + int t; + char *s; + int n; +{ + if (tt.tt_nmodes != tt.tt_modes) + zz_setmodes(tt.tt_nmodes); + if (zz_debug) { + char buf[100]; + zz_setmodes(WWM_REV); + (void) sprintf(buf, "%02x>", t); + ttputs(buf); + tt.tt_col += 3; + } + ttputc(t + 0x81); +} + +int +zz_rint(p, n) + char *p; + int n; +{ + int i; + char *q; + + if (!zz_ecc) + return n; + for (i = n, q = p; --i >= 0;) { + int c = (unsigned char) *p++; + + if (zz_lastc == 0) { + switch (c) { + case 0: + *q++ = 0; + zz_lastc = -1; + break; + case 1: /* start input ecc */ + zz_ecc = 2; + zz_lastc = -1; + wwnreadstat++; + break; + case 2: /* ack checkpoint */ + tt.tt_ack = 1; + zz_lastc = -1; + wwnreadack++; + break; + case 3: /* nack checkpoint */ + tt.tt_ack = -1; + zz_lastc = -1; + wwnreadnack++; + break; + default: + zz_lastc = c; + wwnreadec++; + } + } else if (zz_ecc == 1) { + if (c) + *q++ = c; + else + zz_lastc = 0; + } else { + if (zz_lastc < 0) { + zz_lastc = c; + } else if (zz_lastc == c) { + *q++ = zz_lastc; + zz_lastc = -1; + } else { + wwnreadec++; + zz_lastc = c; + } + } + } + return q - (p - n); +} + +void +zz_checksum(p, n) + char *p; + int n; +{ + while (--n >= 0) { + int c = *p++ & 0x7f; + c ^= zz_sum; + zz_sum = c << 1 | (c >> 11 & 1); + } +} + +void +zz_compress(flag) + int flag; +{ + if (flag) + tt.tt_checksum = 0; + else + tt.tt_checksum = zz_checksum; +} + +void +zz_checkpoint() +{ + static char x[] = { ctrl('['), 'V', 0, 0 }; + + zz_checksum(x, sizeof x); + ttesc('V'); + ttputc(' ' + (zz_sum & 0x3f)); + ttputc(' ' + (zz_sum >> 6 & 0x3f)); + ttflush(); + zz_sum = 0; +} + +int +tt_zapple() +{ + tt.tt_insspace = zz_insspace; + tt.tt_delchar = zz_delchar; + tt.tt_insline = zz_insline; + tt.tt_delline = zz_delline; + tt.tt_clreol = zz_clreol; + tt.tt_clreos = zz_clreos; + tt.tt_scroll_down = zz_scroll_down; + tt.tt_scroll_up = zz_scroll_up; + tt.tt_setscroll = zz_setscroll; + tt.tt_availmodes = WWM_REV; + tt.tt_wrap = 1; + tt.tt_retain = 0; + tt.tt_ncol = NCOL; + tt.tt_nrow = NROW; + tt.tt_start = zz_start; + tt.tt_reset = zz_reset; + tt.tt_end = zz_end; + tt.tt_write = zz_write; + tt.tt_putc = zz_putc; + tt.tt_move = zz_move; + tt.tt_clear = zz_clear; + tt.tt_setmodes = zz_setmodes; + tt.tt_frame = gen_frame; + tt.tt_padc = TT_PADC_NONE; + tt.tt_ntoken = 127; + tt.tt_set_token = zz_set_token; + tt.tt_put_token = zz_put_token; + tt.tt_token_min = 1; + tt.tt_token_max = TOKEN_MAX; + tt.tt_set_token_cost = 2; + tt.tt_put_token_cost = 1; + tt.tt_compress = zz_compress; + tt.tt_checksum = zz_checksum; + tt.tt_checkpoint = zz_checkpoint; + tt.tt_reset = zz_reset; + tt.tt_rint = zz_rint; + return 0; +} diff --git a/window/ttzentec.c b/window/ttzentec.c new file mode 100644 index 0000000..5907404 --- /dev/null +++ b/window/ttzentec.c @@ -0,0 +1,74 @@ +/* $NetBSD: ttzentec.c,v 1.4 1997/11/21 08:36:44 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)ttzentec.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ttzentec.c,v 1.4 1997/11/21 08:36:44 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Zentec 1021 + * + * We let the termcap entry specify how to enter and exit graphics mode, + * since it varies with what the terminal is emulating. + */ + +#define G (WWM_GRP << WWC_MSHIFT) +short zentec_frame[16] = { + ' ', 'x'|G, 'q'|G, 'm'|G, + 'x'|G, 'x'|G, 'l'|G, 't'|G, + 'q'|G, 'j'|G, 'q'|G, 'v'|G, + 'k'|G, 'u'|G, 'w'|G, 'n'|G +}; + +int +tt_zentec() +{ + if (tt_generic() < 0) + return -1; + if (tt.tt_availmodes | WWM_GRP) + tt.tt_frame = zentec_frame; + return 0; +} diff --git a/window/value.h b/window/value.h new file mode 100644 index 0000000..d6b051f --- /dev/null +++ b/window/value.h @@ -0,0 +1,55 @@ +/* $NetBSD: value.h,v 1.3 1995/09/28 10:35:00 tls Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)value.h 8.1 (Berkeley) 6/6/93 + */ + +struct value { + char v_type; + union { + int V_num; + char *V_str; + } v_un; +}; +#define v_num v_un.V_num +#define v_str v_un.V_str + +#define V_NUM 1 +#define V_STR 2 +#define V_ERR 3 + +#define val_free(v) ((v).v_type == V_STR ? str_free((v).v_str) : 0) diff --git a/window/var.c b/window/var.c new file mode 100644 index 0000000..8fddabc --- /dev/null +++ b/window/var.c @@ -0,0 +1,168 @@ +/* $NetBSD: var.c,v 1.5 1997/11/21 08:36:45 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)var.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: var.c,v 1.5 1997/11/21 08:36:45 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "value.h" +#define EXTERN +#include "var.h" +#undef EXTERN +#include "window_string.h" + +struct var * +var_set1(head, name, v) + struct var **head; + char *name; + struct value *v; +{ + struct var **p; + struct var *r; + struct value val; + + /* do this first, easier to recover */ + val = *v; + if (val.v_type == V_STR && val.v_str != 0 && + (val.v_str = str_cpy(val.v_str)) == 0) + return 0; + if (*(p = var_lookup1(head, name)) == 0) { + r = (struct var *) malloc(sizeof (struct var)); + if (r == 0) { + val_free(val); + return 0; + } + if ((r->r_name = str_cpy(name)) == 0) { + val_free(val); + free((char *) r); + return 0; + } + r->r_left = r->r_right = 0; + *p = r; + } else { + r = *p; + val_free(r->r_val); + } + r->r_val = val; + return r; +} + +struct var * +var_setstr1(head, name, str) + struct var **head; + char *name; + char *str; +{ + struct value v; + + v.v_type = V_STR; + v.v_str = str; + return var_set1(head, name, &v); +} + +struct var * +var_setnum1(head, name, num) + struct var **head; + char *name; + int num; +{ + struct value v; + + v.v_type = V_NUM; + v.v_num = num; + return var_set1(head, name, &v); +} + +int +var_unset1(head, name) + struct var **head; + char *name; +{ + struct var **p; + struct var *r; + + if (*(p = var_lookup1(head, name)) == 0) + return -1; + r = *p; + *p = r->r_left; + while (*p != 0) + p = &(*p)->r_right; + *p = r->r_right; + val_free(r->r_val); + str_free(r->r_name); + free((char *) r); + return 0; +} + +struct var ** +var_lookup1(p, name) + struct var **p; + char *name; +{ + int cmp; + + while (*p != 0) { + if ((cmp = strcmp(name, (*p)->r_name)) < 0) + p = &(*p)->r_left; + else if (cmp > 0) + p = &(*p)->r_right; + else + break; + } + return p; +} + +int +var_walk1(r, func, a) + struct var *r; + int (*func) __P((void *, struct var *)); + void *a; +{ + if (r == 0) + return 0; + if (var_walk1(r->r_left, func, a) < 0 || (*func)(a, r) < 0 + || var_walk1(r->r_right, func, a) < 0) + return -1; + return 0; +} diff --git a/window/var.h b/window/var.h new file mode 100644 index 0000000..2df1087 --- /dev/null +++ b/window/var.h @@ -0,0 +1,67 @@ +/* $NetBSD: var.h,v 1.4 1997/11/21 08:36:46 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)var.h 8.1 (Berkeley) 6/6/93 + */ + +#ifndef EXTERN +#define EXTERN extern +#endif + +struct var { + struct var *r_left; + struct var *r_right; + char *r_name; + struct value r_val; +}; + +struct var **var_lookup1 __P((struct var **, char *)); +struct var *var_set1 __P((struct var **, char *, struct value *)); +struct var *var_setnum1 __P((struct var **, char *, int)); +struct var *var_setstr1 __P((struct var **, char *, char *)); +int var_unset1 __P((struct var **, char *)); +int var_walk1 __P((struct var *, int (*func)(void *, struct var *), + void *)); + +#define var_set(n, v) var_set1(&var_head, n, v) +#define var_setstr(n, s) var_setstr1(&var_head, n, s) +#define var_setnum(n, i) var_setnum1(&var_head, n, i) +#define var_unset(n) var_unset1(&var_head, n) +#define var_lookup(n) (*var_lookup1(&var_head, n)) +#define var_walk(f, a) var_walk1(var_head, f, a) + +EXTERN struct var *var_head; /* secret, shhh */ diff --git a/window/win.c b/window/win.c new file mode 100644 index 0000000..830f052 --- /dev/null +++ b/window/win.c @@ -0,0 +1,396 @@ +/* $NetBSD: win.c,v 1.10 1998/08/25 20:59:43 ross Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)win.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: win.c,v 1.10 1998/08/25 20:59:43 ross Exp $"); +#endif +#endif /* not lint */ + +#include +#include "defs.h" +#include "char.h" +#include "window_string.h" + +/* + * Higher level routines for dealing with windows. + * + * There are two types of windows: user window, and information window. + * User windows are the ones with a pty and shell. Information windows + * are for displaying error messages, and other information. + * + * The windows are doubly linked in overlapping order and divided into + * two groups: foreground and normal. Information + * windows are always foreground. User windows can be either. + * Addwin() adds a window to the list at the top of one of the two groups. + * Deletewin() deletes a window. Front() moves a window to the front + * of its group. Wwopen(), wwadd(), and wwdelete() should never be called + * directly. + */ + +/* + * Open a user window. + */ +struct ww * +openwin(id, row, col, nrow, ncol, nline, label, type, uflags, shf, sh) + int id, row, col, nrow, ncol, nline; + char *label; + int type, uflags; + char *shf, **sh; +{ + struct ww *w; + + if (id < 0 && (id = findid()) < 0) + return 0; + if (row + nrow <= 0 || row > wwnrow - 1 + || col + ncol <= 0 || col > wwncol - 1) { + error("Illegal window position."); + return 0; + } + w = wwopen(type, 0, nrow, ncol, row, col, nline); + if (w == 0) { + error("Can't open window: %s.", wwerror()); + return 0; + } + w->ww_id = id; + window[id] = w; + CLR(w->ww_uflags, WWU_ALLFLAGS); + SET(w->ww_uflags, uflags); + w->ww_alt = w->ww_w; + if (label != 0 && setlabel(w, label) < 0) + error("No memory for label."); + wwcursor(w, 1); + /* + * We have to do this little maneuver to make sure + * addwin() puts w at the top, so we don't waste an + * insert and delete operation. + */ + setselwin((struct ww *)0); + addwin(w, 0); + setselwin(w); + if (wwspawn(w, shf, sh) < 0) { + error("Can't execute %s: %s.", shf, wwerror()); + closewin(w); + return 0; + } + return w; +} + +int +findid() +{ + int i; + + for (i = 0; i < NWINDOW && window[i] != 0; i++) + ; + if (i >= NWINDOW) { + error("Too many windows."); + return -1; + } + return i; +} + +struct ww * +findselwin() +{ + struct ww *w, *s = 0; + int i; + + for (i = 0; i < NWINDOW; i++) + if ((w = window[i]) != 0 && w != selwin && + (s == 0 || + (!isfg(w) && (w->ww_order < s->ww_order || isfg(s))))) + s = w; + return s; +} + +/* + * Close a user window. Close all if w == 0. + */ +void +closewin(w) + struct ww *w; +{ + char didit = 0; + int i; + + if (w != 0) { + closewin1(w); + didit++; + } else + for (i = 0; i < NWINDOW; i++) { + if ((w = window[i]) == 0) + continue; + closewin1(w); + didit++; + } + if (didit) { + if (selwin == 0) { + if (lastselwin != 0) { + setselwin(lastselwin); + lastselwin = 0; + } else if ((w = findselwin())) + setselwin(w); + } + if (lastselwin == 0 && selwin) + if ((w = findselwin())) + lastselwin = w; + reframe(); + } +} + +/* + * Open an information (display) window. + */ +struct ww * +openiwin(nrow, label) + int nrow; + char *label; +{ + struct ww *w; + + if ((w = wwopen(WWT_INTERNAL, 0, nrow, wwncol, 2, 0, 0)) == 0) + return 0; + SET(w->ww_wflags, WWW_MAPNL | WWW_NOINTR | WWW_NOUPDATE | WWW_UNCTRL); + SET(w->ww_uflags, WWU_HASFRAME | WWU_CENTER); + w->ww_id = -1; + (void) setlabel(w, label); + addwin(w, 1); + reframe(); + return w; +} + +/* + * Close an information window. + */ +void +closeiwin(w) + struct ww *w; +{ + closewin1(w); + reframe(); +} + +void +closewin1(w) + struct ww *w; +{ + if (w == selwin) + selwin = 0; + if (w == lastselwin) + lastselwin = 0; + if (w->ww_id >= 0 && w->ww_id < NWINDOW) + window[w->ww_id] = 0; + if (w->ww_label) + str_free(w->ww_label); + deletewin(w); + wwclose(w); +} + +/* + * Move the window to the top of its group. + * Don't do it if already fully visible. + * Wwvisible() doesn't work for tinted windows. + * But anything to make it faster. + * Always reframe() if doreframe is true. + */ +void +front(w, doreframe) + struct ww *w; + char doreframe; +{ + if (w->ww_back != (isfg(w) ? framewin : fgwin) && !wwvisible(w)) { + deletewin(w); + addwin(w, isfg(w)); + doreframe = 1; + } + if (doreframe) + reframe(); +} + +/* + * Add a window at the top of normal windows or foreground windows. + * For normal windows, we put it behind the current window. + */ +void +addwin(w, fg) + struct ww *w; + char fg; +{ + if (fg) { + wwadd(w, framewin); + if (fgwin == framewin) + fgwin = w; + } else + wwadd(w, selwin != 0 && selwin != w && !isfg(selwin) + ? selwin : fgwin); +} + +/* + * Delete a window. + */ +void +deletewin(w) + struct ww *w; +{ + if (fgwin == w) + fgwin = w->ww_back; + wwdelete(w); +} + +void +reframe() +{ + struct ww *w; + + wwunframe(framewin); + for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back) + if (ISSET(w->ww_uflags, WWU_HASFRAME)) { + wwframe(w, framewin); + labelwin(w); + } +} + +void +labelwin(w) + struct ww *w; +{ + int mode = w == selwin ? WWM_REV : 0; + + if (!ISSET(w->ww_uflags, WWU_HASFRAME)) + return; + if (w->ww_id >= 0) { + char buf[2]; + + buf[0] = w->ww_id + '1'; + buf[1] = 0; + wwlabel(w, framewin, 1, buf, mode); + } + if (w->ww_label) { + int col; + + if (ISSET(w->ww_uflags, WWU_CENTER)) { + col = (w->ww_w.nc - strlen(w->ww_label)) / 2; + col = MAX(3, col); + } else + col = 3; + wwlabel(w, framewin, col, w->ww_label, mode); + } +} + +void +stopwin(w) + struct ww *w; +{ + if (w->ww_pty >= 0 && w->ww_type == WWT_PTY && wwstoptty(w->ww_pty) < 0) + error("Can't stop output: %s.", wwerror()); + else + SET(w->ww_pflags, WWP_STOPPED); +} + +void +startwin(w) + struct ww *w; +{ + if (w->ww_pty >= 0 && w->ww_type == WWT_PTY && + wwstarttty(w->ww_pty) < 0) + error("Can't start output: %s.", wwerror()); + else + CLR(w->ww_pflags, WWP_STOPPED); +} + +void +sizewin(w, nrow, ncol) + struct ww *w; + int nrow, ncol; +{ + struct ww *back = w->ww_back; + + w->ww_alt.nr = w->ww_w.nr; + w->ww_alt.nc = w->ww_w.nc; + wwdelete(w); + if (wwsize(w, nrow, ncol) < 0) + error("Can't resize window: %s.", wwerror()); + wwadd(w, back); + reframe(); +} + +void +waitnl(w) + struct ww *w; +{ + (void) waitnl1(w, "[Type any key to continue]"); +} + +int +more(w, always) + struct ww *w; + char always; +{ + int c; + int uc = ISSET(w->ww_wflags, WWW_UNCTRL); + + if (!always && w->ww_cur.r < w->ww_w.b - 2) + return 0; + c = waitnl1(w, "[Type escape to abort, any other key to continue]"); + CLR(w->ww_wflags, WWW_UNCTRL); + wwputs("\033E", w); + SET(w->ww_wflags, uc); + return c == ctrl('[') ? 2 : 1; +} + +int +waitnl1(w, prompt) + struct ww *w; + char *prompt; +{ + int uc = ISSET(w->ww_wflags, WWW_UNCTRL); + + CLR(w->ww_wflags, WWW_UNCTRL); + front(w, 0); + wwprintf(w, "\033Y%c%c\033sA%s\033rA ", + w->ww_w.nr - 1 + ' ', ' ', prompt); /* print on last line */ + wwcurtowin(w); + while (wwpeekc() < 0) + wwiomux(); + SET(w->ww_wflags, uc); + return wwgetc(); +} diff --git a/window/window.1 b/window/window.1 new file mode 100644 index 0000000..1f9c1df --- /dev/null +++ b/window/window.1 @@ -0,0 +1,949 @@ +.\" $NetBSD: window.1,v 1.5 1997/11/21 08:36:50 lukem Exp $ +.\" +.\" Copyright (c) 1985, 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Edward Wang at The University of California, Berkeley. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)window.1 8.2 (Berkeley) 12/30/93 +.\" +.Dd December 30, 1993 +.Dt WINDOW 1 +.Os BSD 4.3 +.Sh NAME +.Nm window +.Nd window environment +.Sh SYNOPSIS +.Nm +.Op Fl t +.Op Fl f +.Op Fl d +.Op Fl e Ar escape-char +.Op Fl c Ar command +.Sh DESCRIPTION +.Nm +implements a window environment on +.Tn ASCII +terminals. +.Pp +A window is a rectangular portion of the physical terminal +screen associated with a set of processes. Its size and +position can be changed by the user at any time. Processes +communicate with their window in the same way they normally +interact with a terminal\-through their standard input, output, +and diagnostic file descriptors. The window program handles the +details of redirecting input and output to and from the +windows. At any one time, only one window can receive +input from the keyboard, but all windows can simultaneously send output +to the display. +.Pp +When +.Nm +starts up, the commands (see long commands below) +contained in the file +.Pa .windowrc +in the user's home directory are +executed. If it does not exist, two equal sized windows spanning +the terminal screen are created by default. +.Pp +The command line options are +.Bl -tag -width Fl +.It Fl t +Turn on terse mode (see +.Ic terse +command below). +.It Fl f +Fast. Don't perform any startup action. +.It Fl d +Ignore +.Pa .windowrc +and create the two default +windows instead. +.It Fl e Ar escape-char +Set the escape character to +.Ar escape-char . +.Ar Escape-char +can be a single character, or in the form +.Ic ^X +where +.Ar X +is any character, meaning +.No control\- Ns Ar X . +.It Fl c Ar command +Execute the string +.Ar command +as a long command (see below) +before doing anything else. +.El +.Pp +Windows can overlap and are framed as necessary. Each window +is named by one of the digits ``1'' to ``9''. This one-character +identifier, as well as a user definable label string, are displayed +with the window on the top edge of its frame. A window can be +designated to be in the +.Ar foreground , +in which case it will always be +on top of all normal, non-foreground windows, and can be covered +only by other foreground windows. A window need not be completely +within the edges of the terminal screen. Thus a large window +(possibly larger than the screen) may be positioned to show only +a portion of its full size. +.Pp +Each window has a cursor and a set of control functions. Most intelligent +terminal operations such as line and +character deletion and insertion are supported. Display modes +such as underlining and reverse video are available if they are +supported by the terminal. In addition, +similar to terminals with multiple pages of memory, +each window has a text buffer which can have more lines than the window +itself. +.Ss Process Environment +With each newly created window, a shell program is spawned with its +process environment tailored to that window. Its standard input, +output, and diagnostic file descriptors are bound to one end of either +a pseudo-terminal +.Xr (pty 4 ) +or a +.Ux +domain socket +.Xr (socketpair 4 ) . +If a pseudo-terminal is used, then its special +characters and modes (see +.Xr stty 1 ) +are copied from the physical +terminal. A +.Xr termcap 5 +entry tailored to this window is created +and passed as environment +.Xr (environ 5 ) +variable +.Ev TERMCAP . +The termcap entry contains the window's size and +characteristics as well as information from the physical terminal, +such as the existence of underline, reverse video, and other display +modes, and the codes produced by the terminal's function keys, +if any. In addition, the window size attributes of the pseudo-terminal +are set to reflect the size of this window, and updated whenever +it is changed by the user. In particular, the editor +.Xr vi 1 +uses +this information to redraw its display. +.Ss Operation +During normal execution, +.Nm +can be in one of two states: +conversation mode and command mode. In conversation mode, the +terminal's real cursor is placed at the cursor position of a particular +window--called the current window--and input from the keyboard is sent +to the process in that window. The current window is always +on top of all other windows, except those in foreground. In addition, +it is set apart by highlighting its identifier and label in reverse video. +.Pp +Typing +.Nm "" Ns 's +escape character (normally +.Ic ^P ) +in conversation +mode switches it into command mode. In command mode, the top line of +the terminal screen becomes the command prompt window, and +.Nm +interprets input from the keyboard as commands to manipulate windows. +.Pp +There are two types of commands: short commands are usually one or two +key strokes; long commands are strings either typed by the user in the +command window (see the +.Dq Ic \&: +command below), or read from a file (see +.Ic source +below). +.Ss Short Commands +Below, +.Ar \&# +represents one of the digits ``1'' to ``9'' +corresponding to the windows 1 to 9. +.Ic ^X +means +.No control\- Ns Ar X , +where +.Ar X +is any character. In particular, +.Ic ^^ +is +.Li control\-^. +.Ar Escape +is the escape key, or +.Ic ^\&[ . +.Bl -tag -width Ds +.It Ar # +Select window +.Ar # +as the current window +and return to conversation mode. +.It Ic \&% Ns Ar # +Select window +.Ar # +but stay in command mode. +.It Ic ^^ +Select the previous window and return to conversation +mode. This is useful for toggling between two windows. +.It Ic escape +Return to conversation mode. +.It Ic ^P +Return to conversation mode and write +.Ic ^P +to the +current window. Thus, typing two +.Ic ^P Ns 's +in conversation +mode sends one to the current window. If the +.Nm +escape is changed to some other character, that +character takes the place of +.Ic ^P +here. +.It Ic ? +List a short summary of commands. +.It Ic ^L +Refresh the screen. +.It Ic q +Exit +.Nm "" . +Confirmation is requested. +.It Ic ^Z +Suspend +.Nm "" . +.It Ic w +Create a new window. The user is prompted for the positions +of the upper left and lower right corners of the window. +The cursor is placed on the screen and the keys ``h'', ``j'', +``k'', and ``l'' +move the cursor left, down, up, and right, respectively. +The keys ``H'', ``J'', ``K'', and ``L'' move the cursor to the respective +limits of the screen. Typing a number before the movement keys +repeats the movement that number of times. Return enters the cursor position +as the upper left corner of the window. The lower right corner +is entered in the same manner. During this process, +the placement of the new window is indicated by a rectangular +box drawn on the screen, corresponding to where the new window +will be framed. Typing escape at any point +cancels this command. +.Pp +This window becomes the current window, +and is given the first available ID. The default buffer size +is used (see +.Ar default_nline +command below). +.Pp +Only fully visible windows can be created this way. +.It Ic c Ns Ar # +Close window +.Ar # . +The process in the window is sent +the hangup signal (see +.Xr kill 1 ) . +.Xr Csh 1 +should +handle this signal correctly and cause no problems. +.It Ic m Ns Ar # +Move window +.Ar # +to another location. A box in the shape +of the window is drawn on +the screen to indicate the new position of the window, and the same keys as +those for the +.Ic w +command are used to position the box. The +window can be moved partially off-screen. +.It Ic M Ns Ar # +Move window +.Ar # +to its previous position. +.It Ic s Ns Ar # +Change the size of window +.Ar # . +The user is prompted +to enter the new lower right corner of the window. A box +is drawn to indicate the new window size. The same +keys used in +.Ic w +and +.Ic m +are used to enter the position. +.It Ic S Ns Ar # +Change window +.Ar # +to its previous size. +.It Ic ^Y +Scroll the current window up by one line. +.It Ic ^E +Scroll the current window down by one line. +.It Ic ^U +Scroll the current window up by half the window size. +.It Ic ^D +Scroll the current window down by half the window size. +.It Ic ^B +Scroll the current window up by the full window size. +.It Ic ^F +Scroll the current window down by the full window size. +.It Ic h +Move the cursor of the current window left by one column. +.It Ic j +Move the cursor of the current window down by one line. +.It Ic k +Move the cursor of the current window up by one line. +.It Ic l +Move the cursor of the current window right by one column. +.It Ic y +Yank. The user is prompted to enter two points within the current +window. Then the content of the current window between those two points +is saved in the yank buffer. +.It Ic p +Put. The content of the yank buffer is written to the current +window as input. +.It Ic ^S +Stop output in the current window. +.It Ic ^Q +Start output in the current window. +.It Ic : +Enter a line to be executed as long commands. +Normal line +editing characters (erase character, erase word, erase line) +are supported. +.El +.Ss Long Commands +Long commands are a sequence of statements +parsed much like a programming language, with a syntax +similar to that of C. Numeric and string expressions and variables +are supported, as well as conditional statements. +.Pp +There are two data types: string and number. A string is a sequence +of letters or digits beginning with a letter. ``_'' and ``.'' are +considered letters. Alternatively, non-alphanumeric characters can +be included in strings by quoting them in ``"'' or escaping them +with ``\\''. In addition, the ``\\'' sequences of C are supported, +both inside and outside quotes (e.g., ``\\n'' is a new line, +``\\r'' a carriage return). For example, these are legal strings: +abcde01234, "&#$^*&#", ab"$#"cd, ab\\$\\#cd, "/usr/ucb/window". +.Pp +A number is an integer value in one of three forms: +a decimal number, an octal number preceded by ``0'', +or a hexadecimal number preceded by ``0x'' or ``0X''. The natural +machine integer size is used (i.e., the signed integer type +of the C compiler). As in C, a non-zero number represents +a boolean true. +.Pp +The character ``#'' begins a comment which terminates at the +end of the line. +.Pp +A statement is either a conditional or an expression. Expression +statements are terminated with a new line or ``;''. To continue +an expression on the next line, terminate the first line with ``\\''. +.Ss Conditional Statement +.Nm +has a single control structure: +the fully bracketed if statement in the form +.Pp +.Bd -literal -offset indent -compact +if then +\t +\t... +elsif then +\t +\t... +else +\t +\t... +endif +.Ed +.Pp +The +.Ic else +and +.Ic elsif +parts are optional, and the latter can +be repeated any number of times. + +must be numeric. +.Ss Expressions +Expressions in +.Nm +are similar to those in the +C language, with most C operators supported on numeric +operands. In addition, some are overloaded to operate on strings. +.Pp +When an expression is used as a statement, its value is discarded +after evaluation. Therefore, only expressions with side +effects (assignments and function calls) are useful as statements. +.Pp +Single valued (no arrays) variables are supported, of both +numeric and string values. Some variables are predefined. They +are listed below. +.Pp +The operators in order of increasing precedence: +.Bl -tag -width Fl +.It Xo +.Aq Va expr1 +.Ic = +.Aq Va expr2 +.Xc +Assignment. The variable of name +.Aq Va expr1 , +which must be string valued, +is assigned the result of +.Aq Va expr2 . +Returns the value of +.Aq Va expr2 . +.It Xo +.Aq Va expr1 +.Ic ? +.Aq Va expr2 +.Ic : +.Aq Va expr3 +.Xc +Returns the value of +.Aq Va expr2 +if +.Aq Va expr1 +evaluates true +(non-zero numeric value); returns the value of +.Aq Va expr3 +otherwise. Only +one of +.Aq Va expr2 +and +.Aq Va expr3 +is evaluated. +.Aq Va Expr1 +must +be numeric. +.It Xo +.Aq Va expr1 +.Ic \&|\&| +.Aq Va expr2 +.Xc +Logical or. Numeric values only. Short circuit evaluation is supported +(i.e., if +.Aq Va expr1 +evaluates true, then +.Aq Va expr2 +is not evaluated). +.It Xo +.Aq Va expr1 +.Ic \&&\&& +.Aq Va expr2 +.Xc +Logical and with short circuit evaluation. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic \&| +.Aq Va expr2 +.Xc +Bitwise or. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic ^ +.Aq Va expr2 +.Xc +Bitwise exclusive or. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic \&& +.Aq Va expr2 +.Xc +Bitwise and. Numeric values only. +.It Xo +.Aq Va expr1 +.Ic == +.Aq Va expr2 , +.Aq Va expr1 +.Ic != +.Aq expr2 +.Xc +Comparison (equal and not equal, respectively). The boolean +result (either 1 or 0) of the comparison is returned. The +operands can be numeric or string valued. One string operand +forces the other to be converted to a string in necessary. +.It Xo +.Aq Va expr1 +.Ic < +.Aq Va expr2 , +.Aq Va expr1 +.Ic > +.Aq Va expr2 , +.Aq Va expr1 +.Ic <= +.Aq Va expr2 , +.Xc +Less than, greater than, less than or equal to, +greater than or equal to. Both numeric and string values, with +automatic conversion as above. +.It Xo +.Aq Va expr1 +.Ic << +.Aq Va expr2 , +.Aq Va expr1 +.Ic >> +.Aq Va expr2 +.Xc +If both operands are numbers, +.Aq Va expr1 +is bit +shifted left (or right) by +.Aq Va expr2 +bits. If +.Aq Va expr1 +is +a string, then its first (or last) +.Aq Va expr2 +characters are +returns (if +.Aq Va expr2 +is also a string, then its length is used +in place of its value). +.It Xo +.Aq Va expr1 +.Ic + +.Aq Va expr2 , +.Aq Va expr1 +.Ic - +.Aq Va expr2 +.Xc +Addition and subtraction on numbers. For ``+'', if one +argument is a string, then the other is converted to a string, +and the result is the concatenation of the two strings. +.It Xo +.Aq Va expr1 +.Ic \&* +.Aq Va expr2 , +.Aq Va expr1 +.Ic \&/ +.Aq Va expr2 , +.Aq Va expr1 +.Ic \&% +.Aq Va expr2 +.Xc +Multiplication, division, modulo. Numbers only. +.It Xo +.Ic \- Ns Aq Va expr , +.Ic ~ Ns Aq Va expr , +.Ic \&! Ns Aq Va expr , +.Ic \&$ Ns Aq Va expr , +.Ic \&$? Ns Aq Va expr +.Xc +The first three are unary minus, bitwise complement and logical complement +on numbers only. The operator, ``$'', takes +.Aq Va expr +and returns +the value of the variable of that name. If +.Aq Va expr +is numeric +with value +.Ar n +and it appears within an alias macro (see below), +then it refers to the nth argument of the alias invocation. ``$?'' +tests for the existence of the variable +.Aq Va expr , +and returns 1 +if it exists or 0 otherwise. +.It Xo +.Ao Va expr Ac Ns Pq Aq Ar arglist +.Xc +Function call. +.Aq Va Expr +must be a string that is the unique +prefix of the name of a builtin +.Nm +function +or the full name of a user defined alias macro. In the case of a builtin +function, +.Aq Ar arglist +can be in one of two forms: +.Bd -literal -offset indent +, , ... +argname1 = , argname2 = , ... +.Ed +.Pp +The two forms can in fact be intermixed, but the result is +unpredictable. Most arguments can be omitted; default values will +be supplied for them. The +.Ar argnames +can be unique prefixes +of the argument names. The commas separating +arguments are used only to disambiguate, and can usually be omitted. +.Pp +Only the first argument form is valid for user defined aliases. Aliases +are defined using the +.Ic alias +builtin function (see below). Arguments +are accessed via a variant of the variable mechanism (see ``$'' operator +above). +.Pp +Most functions return value, but some are used for side effect +only and so must be used as statements. When a function or an alias is used +as a statement, the parentheses surrounding +the argument list may be omitted. Aliases return no value. +.El +.Ss Builtin Functions +The arguments are listed by name in their natural +order. Optional arguments are in square brackets +.Sq Op . +Arguments +that have no names are in angle brackets +.Sq <> . +An argument meant to be a boolean flag (often named +.Ar flag ) +can be one of +.Ar on , +.Ar off , +.Ar yes , +.Ar no , +.Ar true , +or +.Ar false , +with +obvious meanings, or it can be a numeric expression, +in which case a non-zero value is true. +.Bl -tag -width Fl +.It Xo +.Ic alias Ns Po Bq Aq Ar string , +.Bq Aq Ar string\-list Pc +.Xc +If no argument is given, all currently defined alias macros are +listed. Otherwise, +.Aq Ar string +is defined as an alias, +with expansion +.Aq Ar string\-list > . +The previous definition of +.Aq Ar string , +if any, is returned. Default for +.Aq Ar string\-list +is no change. +.It Ic close Ns Pq Aq Ar window\-list +Close the windows specified in +.Aq Ar window\-list . +If +.Aq Ar window\-list +is the word +.Ar all , +than all windows are closed. No value is returned. +.It Ic cursormodes Ns Pq Bq Ar modes +Set the window cursor to +.Ar modes . +.Ar Modes +is the bitwise +or of the mode bits defined as the variables +.Ar m_ul +(underline), +.Ar m_rev +(reverse video), +.Ar m_blk +(blinking), +and +.Ar m_grp +(graphics, terminal dependent). Return +value is the previous modes. Default is no change. +For example, +.Li cursor($m_rev$m_blk) +sets the window cursors to blinking +reverse video. +.It Ic default_nline Ns Pq Bq Ar nline +Set the default buffer size to +.Ar nline . +Initially, it is +48 lines. Returns the old default buffer size. Default is +no change. Using a very large buffer can slow the program down +considerably. +.It Ic default_shell Ns Pq Bq Aq Ar string\-list +Set the default window shell program to +.Aq Ar string\-list . +Returns +the first string in the old shell setting. Default is no change. Initially, +the default shell is taken from the environment variable +.Ev SHELL . +.It Ic default_smooth Ns Pq Bq Ar flag +Set the default value of the +.Ar smooth +argument +to the command +.Nm +(see below). The argument +is a boolean flag (one of +.Ar on , +.Ar off , +.Ar yes , +.Ar no , +.Ar true , +.Ar false , +or a number, +as described above). Default is no change. +The old value (as a number) is returned. +The initial value is 1 (true). +.It Xo +.Ic echo Ns ( Op Ar window , +.Bq Aq Ar string\-list ) +.Xc +Write the list of strings, +.Aq Ar string-list , +to +.Nm "" , +separated +by spaces and terminated with a new line. The strings are only +displayed in the window, the processes in the window are not +involved (see +.Ic write +below). No value is returned. Default +is the current window. +.It Ic escape Ns Pq Bq Ar escapec +Set the escape character to +.Ar escape-char . +Returns the old +escape character as a one-character string. Default is no +change. +.Ar Escapec +can be a string of a single character, or +in the form +.Fl ^X , +meaning +.No control\- Ns Ar X . +.It Xo +.Ic foreground Ns ( Bq Ar window , +.Bq Ar flag ) +.Xc +Move +.Nm +in or out of foreground. +.Ar Flag +is a boolean value. The old foreground flag +is returned. Default for +.Nm +is the current window, +default for +.Ar flag +is no change. +.It Xo +.Ic label Ns ( Bq Ar window , +.Bq Ar label ) +.Xc +Set the label of +.Nm +to +.Ar label . +Returns the old +label as a string. Default for +.Nm +is the current +window, default for +.Ar label +is no change. To turn +off a label, set it to an empty string (""). +.It Ic list Ns Pq +No arguments. List the identifiers and labels of all windows. No +value is returned. +.It Ic select Ns Pq Bq Ar window +Make +.Nm +the current window. The previous current window +is returned. Default is no change. +.It Ic source Ns Pq Ar filename +Read and execute the long commands in +.Ar filename . +Returns \-1 if the file cannot be read, 0 otherwise. +.It Ic terse Ns Pq Bq flag +Set terse mode to +.Ar flag . +In terse mode, the command window +stays hidden even in command mode, and errors are reported by +sounding the terminal's bell. +.Ar Flag +can take on the same +values as in +.Ar foreground +above. Returns the old terse flag. +Default is no change. +.It Ic unalias Ns Pq Ar alias +Undefine +.Ar alias . +Returns -1 if +.Ar alias +does not exist, +0 otherwise. +.It Ic unset Ns Pq Ar variable +Undefine +.Ar variable . +Returns -1 if +.Ar variable +does not exist, +0 otherwise. +.It Ic variables Ns Pq +No arguments. List all variables. No value is returned. +.It Xo +.Ic window Ns ( Bq Ar row , +.Bq Ar column , +.Bq Ar nrow , +.Bq Ar ncol , +.Bq Ar nline , +.Bq Ar label , +.Bq Ar pty , +.Bq Ar frame , +.Bq Ar mapnl , +.Bq Ar keepopen , +.Bq Ar smooth , +.Bq Ar shell ) . +.Xc +Open a window with upper left corner at +.Ar row , +.Ar column +and size +.Ar nrow , +.Ar ncol . +If +.Ar nline +is specified, +then that many lines are allocated for the text buffer. Otherwise, +the default buffer size is used. Default values for +.Ar row , +.Ar column , +.Ar nrow , +and +.Ar ncol +are, respectively, +the upper, left-most, lower, or right-most extremes of the +screen. +.Ar Label +is the label string. +.Ar Frame , +.Ar pty , +and +.Ar mapnl +are flag values +interpreted in the same way as the argument to +.Ar foreground +(see above); +they mean, respectively, put a frame around this window (default true), +allocate pseudo-terminal for this window rather than socketpair (default +true), and map new line characters in this window to carriage return +and line feed (default true if socketpair is used, false otherwise). +Normally, a window is automatically closed when its process +exits. Setting +.Ar keepopen +to true (default false) prevents this +action. When +.Ar smooth +is true, the screen is updated more frequently +(for this window) to produce a more terminal-like behavior. +The default value of +.Ar smooth +is set by the +.Ar default_smooth +command (see above). +.Ar Shell +is a list of strings that will be used as the shell +program to place in the window (default is the program specified +by +.Ar default_shell , +see above). The created window's identifier +is returned as a number. +.It Xo +.Ic write Ns ( Bq Ar window , +.Bq Aq Ar string\-list ) +.Xc +Send the list of strings, +.Aq Ar string-list , +to +.Nm "" , +separated +by spaces but not terminated with a new line. The strings are actually +given to the window as input. No value is returned. Default +is the current window. +.El +.Ss Predefined Variables +These variables are for information only. Redefining them does +not affect the internal operation of +.Nm "" . +.Bl -tag -width modes +.It Ar baud +The baud rate as a number between 50 and 38400. +.It Ar modes +The display modes (reverse video, underline, blinking, graphics) +supported by the physical terminal. The value of +.Ar modes +is the bitwise or of some of the one bit values, +.Ar m_blk , +.Ar m_grp , +.Ar m_rev , +and +.Ar m_ul +(see below). +These values are useful +in setting the window cursors' modes (see +.Ar cursormodes +above). +.It Ar m_blk +The blinking mode bit. +.It Ar m_grp +The graphics mode bit (not very useful). +.It Ar m_rev +The reverse video mode bit. +.It Ar m_ul +The underline mode bit. +.It Ar ncol +The number of columns on the physical screen. +.It Ar nrow +The number of rows on the physical screen. +.It Ar term +The terminal type. The standard name, found in the second name +field of the terminal's +.Ev TERMCAP +entry, is used. +.Sh ENVIRONMENT +.Nm +utilizes these environment variables: +.Ev HOME , +.Ev SHELL , +.Ev TERM , +.Ev TERMCAP , +.Ev WINDOW_ID . +.Sh FILES +.Bl -tag -width /dev/[pt]ty[pq]? -compact +.It Pa ~/.windowrc +startup command file. +.It Pa /dev/[pt]ty[pq]? +pseudo-terminal devices. +.El +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.3 . +.Sh DIAGNOSTICS +Should be self explanatory. diff --git a/window/window_string.h b/window/window_string.h new file mode 100644 index 0000000..4432ad7 --- /dev/null +++ b/window/window_string.h @@ -0,0 +1,79 @@ +/* $NetBSD: string.h,v 1.4 1997/11/21 08:36:22 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)string.h 8.1 (Berkeley) 6/6/93 + */ + +#ifndef _W_STRING_H_ +#define _W_STRING_H_ + +#include + +#ifndef EXTERN +#define EXTERN extern +#endif + +#define STR_DEBUG + +char *str_cat __P((char *, char *)); +char *str_cpy __P((char *)); +char *str_itoa __P((int)); +int str_match __P((char *, char *, int)); +char *str_ncpy __P((char *, int)); + +#define str_cmp(a, b) strcmp(a, b) + +#ifdef STR_DEBUG +struct string { + struct string *s_forw; + struct string *s_back; + char s_data[1]; +}; + +EXTERN struct string str_head; + +#define str_offset ((unsigned)str_head.s_data - (unsigned)&str_head) +#define str_stos(s) ((struct string *)((unsigned)(s) - str_offset)) + +char *str_alloc __P((size_t)); +void str_free __P((char *)); +#else +#define str_free(s) free(s) +#define str_alloc(s) malloc(s) +#endif + +#endif /* _W_STRING_H_ */ diff --git a/window/windowrc b/window/windowrc new file mode 100644 index 0000000..57c695a --- /dev/null +++ b/window/windowrc @@ -0,0 +1,85 @@ +# Copyright (c) 1983, 1993 +# The Regents of the University of California. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the University of +# California, Berkeley and its contributors. +# 4. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# @(#)windowrc 8.1 (Berkeley) 6/6/93 +# + +# Configuration file example for window manager +# To be installed in ~/.windowrc +# +# Create two unequal sized windows of full screen width, +# and set up some useful aliases. +# + +# +# Optional settings +# +# terse on # set terse mode +# escape "^A" # set escape character +# nline 100 # set default buffer size + # initially, this is 48 + +# +# Make two windows +# The bottom one is MIN(24, total lines * 3 / 4) lines +# The top one is the rest of the screen. +# +three_fourth = $nrow - ((_ = $nrow * 3 / 4) > 24 ? 24 : $_) +unset _ +window row = 0, nrow = $three_fourth - 1, label = "Top" +window row = $three_fourth, label = "Local" + +# +# Useful aliases +# +# +# Standard window +# +alias std "window r = $three_fourth, l = $?1 ? $1 : ''" +# +# Sysline, add your own options +# +alias sysline "_ = select();" \ + "foreground window(r = 0, nr = 1, nc = $ncol + 1, nl = 0," \ + "l = sysline, pty = no, frame = no, sh = sysline \\-w), 1;" \ + "select $_; unset _" +# +# Rlogin +# +alias rlogin "window r = $three_fourth, l = $1, pty = no, mapnl = no," \ + "sh = sh \\-c 'echo $TERMCAP | rsh ' + $1 + ' \\'cat > .TERMCAP\\' ;" \ + "exec rlogin ' + $1" +alias rl rlogin \$1 +# +# Two equal windows +# +alias two "window r = 1, nr = $nrow / 2 - 1, l = top;" \ + "window r = $nrow / 2 + 1, l = bottom" diff --git a/window/ww.h b/window/ww.h new file mode 100644 index 0000000..9f4799f --- /dev/null +++ b/window/ww.h @@ -0,0 +1,399 @@ +/* $NetBSD: ww.h,v 1.12 1998/07/26 15:28:20 mycroft Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ww.h 8.1 (Berkeley) 6/6/93 + */ + +#ifndef __WW_H__ +#define __WW_H__ + +#include +#ifdef OLD_TTY +#include +#else +#include +#endif +#include + +#if __STDC__ +#include +#else +#include +#endif +#include + +#ifndef EXTERN +#define EXTERN extern +#endif + +#define NWW 30 /* maximum number of windows */ + +/* Macros to clear/set/test flags. */ +#define SET(t, f) (t) |= (f) +#define CLR(t, f) (t) &= ~(f) +#define ISSET(t, f) ((t) & (f)) + + /* a rectangle */ +struct ww_dim { + int nr; /* number of rows */ + int nc; /* number of columns */ + int t, b; /* top, bottom */ + int l, r; /* left, right */ +}; + + /* a coordinate */ +struct ww_pos { + int r; /* row */ + int c; /* column */ +}; + + /* the window structure */ +struct ww { + int ww_flags; + + /* general flags and states */ + int ww_state; /* state of window */ +#define WWS_INITIAL 0 /* just opened */ +#define WWS_HASPROC 1 /* has process on pty */ +#define WWS_DEAD 3 /* child died */ +#define ww_oflags ww_flags +#define WWO_REVERSE 0x0001 /* make it all reverse video */ +#define WWO_GLASS 0x0002 /* make it all glass */ +#define WWO_FRAME 0x0004 /* this is a frame window */ +#define WWO_ALLFLAGS 0x0007 + + /* information for overlap */ + struct ww *ww_forw; /* doubly linked list, for overlapping info */ + struct ww *ww_back; + unsigned char ww_index; /* the window index, for wwindex[] */ +#define WWX_NOBODY NWW + int ww_order; /* the overlapping order */ + + /* sizes and positions */ + struct ww_dim ww_w; /* window size and pos */ + struct ww_dim ww_b; /* buffer size and pos */ + struct ww_dim ww_i; /* the part inside the screen */ + struct ww_pos ww_cur; /* the cursor position, relative to ww_w */ + + /* arrays */ + char **ww_win; /* the window */ + union ww_char **ww_buf; /* the buffer */ + char **ww_fmap; /* map for frame and box windows */ + short *ww_nvis; /* how many ww_buf chars are visible per row */ + + /* information for wwwrite() and company */ + int ww_wstate; /* state for outputting characters */ + char ww_modes; /* current display modes */ +#define ww_wflags ww_flags +#define WWW_INSERT 0x0008 /* insert mode */ +#define WWW_MAPNL 0x0010 /* map \n to \r\n */ +#define WWW_NOUPDATE 0x0020 /* don't do updates in wwwrite() */ +#define WWW_UNCTRL 0x0040 /* expand control characters */ +#define WWW_NOINTR 0x0080 /* wwwrite() not interruptable */ +#define WWW_HASCURSOR 0x0100 /* has fake cursor */ + + /* things for the window process and io */ + int ww_type; +#define WWT_PTY 0 /* pty */ +#define WWT_SOCKET 1 /* socket pair */ +#define WWT_INTERNAL 2 +#define ww_pflags ww_flags +#define WWP_STOPPED 0x0200 /* output stopped */ + int ww_pty; /* file descriptor of pty or socket pair */ + int ww_socket; /* other end of socket pair */ + int ww_pid; /* pid of process, if WWS_HASPROC true */ + char ww_ttyname[11]; /* "/dev/ttyp?" */ + char *ww_ob; /* output buffer */ + char *ww_obe; /* end of ww_ob */ + char *ww_obp; /* current read position in ww_ob */ + char *ww_obq; /* current write position in ww_ob */ + + /* things for the user, they really don't belong here */ + int ww_id; /* the user window id */ +#define ww_uflags ww_flags +#define WWU_CENTER 0x0400 /* center the label */ +#define WWU_HASFRAME 0x0800 /* frame it */ +#define WWU_KEEPOPEN 0x1000 /* keep it open after the process dies */ +#define WWU_ALLFLAGS 0x1c00 + char *ww_label; /* the user supplied label */ + struct ww_dim ww_alt; /* alternate position and size */ +}; + + /* state of a tty */ +struct ww_tty { +#ifdef OLD_TTY + struct sgttyb ww_sgttyb; + struct tchars ww_tchars; + struct ltchars ww_ltchars; + int ww_lmode; + int ww_ldisc; +#else + struct termios ww_termios; +#endif +}; + +union ww_char { + short c_w; /* as a word */ + struct { +#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN + char C_c; /* the character part */ + char C_m; /* the mode part */ +#endif +#if BYTE_ORDER == BIG_ENDIAN + char C_m; /* the mode part */ + char C_c; /* the character part */ +#endif + } c_un; +}; +#define c_c c_un.C_c +#define c_m c_un.C_m + + /* for display update */ +struct ww_update { + int best_gain; + int best_col; + int gain; +}; + + /* parts of ww_char */ +#define WWC_CMASK 0x00ff +#define WWC_MMASK 0xff00 +#define WWC_MSHIFT 8 + + /* c_m bits */ +#define WWM_REV 0x01 /* reverse video */ +#define WWM_BLK 0x02 /* blinking */ +#define WWM_UL 0x04 /* underlined */ +#define WWM_GRP 0x08 /* graphics */ +#define WWM_DIM 0x10 /* half intensity */ +#define WWM_USR 0x20 /* user specified mode */ +#define WWM_GLS 0x40 /* window only, glass, i.e., transparent */ + + /* flags for ww_fmap */ +#define WWF_U 0x01 +#define WWF_R 0x02 +#define WWF_D 0x04 +#define WWF_L 0x08 +#define WWF_MASK (WWF_U|WWF_R|WWF_D|WWF_L) +#define WWF_LABEL 0x40 +#define WWF_TOP 0x80 + + /* error codes */ +#define WWE_NOERR 0 +#define WWE_SYS 1 /* system error */ +#define WWE_NOMEM 2 /* out of memory */ +#define WWE_TOOMANY 3 /* too many windows */ +#define WWE_NOPTY 4 /* no more ptys */ +#define WWE_SIZE 5 /* bad window size */ +#define WWE_BADTERM 6 /* bad terminal type */ +#define WWE_CANTDO 7 /* dumb terminal */ + + /* wwtouched[] bits, there used to be more than one */ +#define WWU_TOUCHED 0x01 /* touched */ + + /* the window structures */ +EXTERN struct ww wwhead; +EXTERN struct ww *wwindex[NWW + 1]; /* last location is for wwnobody */ +EXTERN struct ww wwnobody; + + /* tty things */ +EXTERN struct ww_tty wwoldtty; /* the old (saved) terminal settings */ +EXTERN struct ww_tty wwnewtty; /* the new (current) terminal settings */ +EXTERN struct ww_tty wwwintty; /* the terminal settings for windows */ +EXTERN char *wwterm; /* the terminal name */ +EXTERN char wwtermcap[1024]; /* place for the termcap */ + + /* generally useful variables */ +EXTERN int wwnrow, wwncol; /* the screen size */ +EXTERN char wwavailmodes; /* actually supported modes */ +EXTERN char wwcursormodes; /* the modes for the fake cursor */ +EXTERN char wwwrap; /* terminal has auto wrap around */ +EXTERN int wwdtablesize; /* result of getdtablesize() call */ +EXTERN unsigned char **wwsmap; /* the screen map */ +EXTERN union ww_char **wwos; /* the old (current) screen */ +EXTERN union ww_char **wwns; /* the new (desired) screen */ +EXTERN union ww_char **wwcs; /* the checkpointed screen */ +EXTERN char *wwtouched; /* wwns changed flags */ +EXTERN struct ww_update *wwupd; /* for display update */ +EXTERN int wwospeed; /* output baud rate, copied from wwoldtty */ +EXTERN int wwbaud; /* wwospeed converted into actual number */ +EXTERN int wwcursorrow, wwcursorcol; /* where we want the cursor to be */ +EXTERN int wwerrno; /* error number */ + + /* statistics */ +EXTERN int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc; +EXTERN int wwnwwr, wwnwwra, wwnwwrc; +EXTERN int wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc; +EXTERN int wwnupdate, wwnupdline, wwnupdmiss; +EXTERN int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline; +EXTERN int wwnread, wwnreade, wwnreadz; +EXTERN int wwnreadc, wwnreadack, wwnreadnack, wwnreadstat, wwnreadec; +EXTERN int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp; +EXTERN int wwnselect, wwnselecte, wwnselectz; + + /* quicky macros */ +#define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c)) +#define wwcurtowin(w) wwsetcursor((w)->ww_cur.r, (w)->ww_cur.c) +#define wwunbox(w) wwunframe(w) +#define wwclreol(w,r,c) wwclreol1((w), (r), (c), 0) +#define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0) +#define wwupdate() wwupdate1(0, wwnrow); + + /* things for handling input */ +EXTERN struct ww *wwcurwin; /* window to copy input into */ +EXTERN char *wwib; /* input (keyboard) buffer */ +EXTERN char *wwibe; /* wwib + sizeof buffer */ +EXTERN char *wwibp; /* current read position in buffer */ +EXTERN char *wwibq; /* current write position in buffer */ +#define wwmaskc(c) ((c) & 0x7f) +#define wwgetc() (wwibp < wwibq ? wwmaskc(*wwibp++) : -1) +#define wwpeekc() (wwibp < wwibq ? wwmaskc(*wwibp) : -1) +#define wwungetc(c) (wwibp > wwib ? *--wwibp = (c) : -1) + + /* things for short circuiting wwiomux() */ +EXTERN char wwintr; /* interrupting */ +EXTERN char wwsetjmp; /* want a longjmp() from wwrint() and wwchild() */ +EXTERN jmp_buf wwjmpbuf; /* jmpbuf for above */ +#define wwinterrupt() wwintr +#define wwsetintr() do { wwintr = 1; if (wwsetjmp) longjmp(wwjmpbuf, 1); } \ + while (0) +#define wwclrintr() (wwintr = 0) + + /* checkpointing */ +EXTERN int wwdocheckpoint; + + /* the window virtual terminal */ +#define WWT_TERM "window-v2" +#define WWT_TERMCAP "WW|window-v2|window program version 2:\ + :am:bs:da:db:ms:pt:cr=^M:nl=^J:bl=^G:ta=^I:\ + :cm=\\EY%+ %+ :le=^H:nd=\\EC:up=\\EA:do=\\EB:ho=\\EH:\ + :cd=\\EJ:ce=\\EK:cl=\\EE:me=\\Er^?:" +#define WWT_REV "se=\\ErA:so=\\EsA:mr=\\EsA:" +#define WWT_BLK "BE=\\ErB:BS=\\EsB:mb=\\EsB:" +#define WWT_UL "ue=\\ErD:us=\\EsD:" +#define WWT_GRP "ae=\\ErH:as=\\EsH:" +#define WWT_DIM "HE=\\ErP:HS=\\EsP:mh=\\EsP:" +#define WWT_USR "XE=\\Er`:XS=\\Es`:" +#define WWT_ALDL "al=\\EL:dl=\\EM:" +#define WWT_IMEI "im=\\E@:ei=\\EO:ic=:mi:" /* XXX, ic for emacs bug */ +#define WWT_IC "ic=\\EP:" +#define WWT_DC "dc=\\EN:" +EXTERN char wwwintermcap[1024]; /* terminal-specific but window-independent + part of the window termcap */ +#ifdef TERMINFO + /* where to put the temporary terminfo directory */ +EXTERN char wwterminfopath[1024]; +#endif + +struct ww *wwopen __P((int, int, int, int, int, int, int)); +void wwadd __P((struct ww *, struct ww *)); +void wwaddcap __P((char *, char **)); +void wwaddcap1 __P((char *, char **)); +void wwalarm __P((int)); +char **wwalloc __P((int, int, int, int, int)); +void wwbell __P((void)); +void wwbox __P((struct ww *, int, int, int, int)); +void wwcheckpoint __P((void)); +void wwchild __P((int)); +void wwclose __P((struct ww *)); +void wwclreol1 __P((struct ww *, int, int, char)); +void wwclreos __P((struct ww *, int, int)); +void wwcopyscreen __P((union ww_char **s1, union ww_char **s2)); +void wwcursor __P((struct ww *, int)); +void wwdelchar __P((struct ww *, int, int)); +void wwdelete __P((struct ww *)); +void wwdelete1 __P((struct ww *, int, int, int, int)); +void wwdelline __P((struct ww *, int)); +void wwdumpns __P((void)); +void wwdumpnvis __P((struct ww *)); +void wwdumpos __P((void)); +void wwdumpsmap __P((void)); +void wwdumpwin __P((struct ww *)); +void wwend __P((int)); +int wwenviron __P((struct ww *)); +const char * + wwerror __P((void)); +void wwflush __P((void)); +void wwframe __P((struct ww *, struct ww *)); +void wwframec __P((struct ww *, int, int, char)); +void wwfree __P((char **, int)); +int wwgetpty __P((struct ww *)); +int wwgettty __P((int, struct ww_tty *)); +int wwgetttysize __P((int, int *, int *)); +void wwgets __P((char *, int, struct ww *)); +int wwinit __P((void)); +void wwinschar __P((struct ww *, int, int, char, char)); +void wwinsline __P((struct ww *, int)); +void wwiomux __P((void)); +void wwlabel __P((struct ww *, struct ww *, int, char *, int)); +void wwmove __P((struct ww *, int, int)); +void wwprintf __P((struct ww *, const char *, ...)); +void wwputc __P((char, struct ww *)); +void wwputs __P((char *, struct ww *)); +void wwredraw __P((void)); +void wwredrawwin1 __P((struct ww *,int, int, int)); +void wwquit __P((int)); +void wwreset __P((void)); +void wwrint __P((void)); +void wwscroll __P((struct ww *, int)); +int wwscroll1 __P((struct ww *, int, int, int, int)); +void wwsetcursormodes __P((int)); +int wwsettty __P((int, struct ww_tty *)); +int wwsetttysize __P((int, int, int)); +int wwsize __P((struct ww *, int, int)); +int wwspawn __P((struct ww *, char *, char **)); +void wwstart __P((void)); +void wwstart1 __P((void)); +int wwstarttty __P((int)); +int wwstoptty __P((int)); +void wwsuspend __P((void)); +void wwunframe __P((struct ww *)); +void wwupdate1 __P((int, int)); +int wwvisible __P((struct ww *)); +void wwvprintf __P((struct ww *, const char *, va_list)); +int wwwrite __P((struct ww *, char *, int)); +#ifdef TERMINFO +int wwterminfoinit __P((void)); +int wwterminfoend __P((void)); +#endif + +#undef MIN +#undef MAX +#define MIN(x, y) ((x) > (y) ? (y) : (x)) +#define MAX(x, y) ((x) > (y) ? (x) : (y)) + +#endif __WW_H__ diff --git a/window/wwadd.c b/window/wwadd.c new file mode 100644 index 0000000..a0311d1 --- /dev/null +++ b/window/wwadd.c @@ -0,0 +1,96 @@ +/* $NetBSD: wwadd.c,v 1.5 1997/11/21 08:36:54 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwadd.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwadd.c,v 1.5 1997/11/21 08:36:54 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +/* + * Stick w1 behind w2. + */ +void +wwadd(w1, w2) + struct ww *w1; + struct ww *w2; +{ + int i; + struct ww *w; + + w1->ww_order = w2->ww_order + 1; + w1->ww_back = w2; + w1->ww_forw = w2->ww_forw; + w2->ww_forw->ww_back = w1; + w2->ww_forw = w1; + + for (w = w1->ww_forw; w != &wwhead; w = w->ww_forw) + w->ww_order++; + for (i = w1->ww_i.t; i < w1->ww_i.b; i++) { + int j; + unsigned char *smap = wwsmap[i]; + char *win = w1->ww_win[i]; + union ww_char *ns = wwns[i]; + union ww_char *buf = w1->ww_buf[i]; + int nvis = 0; + int nchanged = 0; + + for (j = w1->ww_i.l; j < w1->ww_i.r; j++) { + w = wwindex[smap[j]]; + if (w1->ww_order > w->ww_order) + continue; + if (win[j] & WWM_GLS) + continue; + if (w != &wwnobody && w->ww_win[i][j] == 0) + w->ww_nvis[i]--; + smap[j] = w1->ww_index; + if (win[j] == 0) + nvis++; + ns[j].c_w = buf[j].c_w ^ win[j] << WWC_MSHIFT; + nchanged++; + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + w1->ww_nvis[i] = nvis; + } +} diff --git a/window/wwalloc.c b/window/wwalloc.c new file mode 100644 index 0000000..fb7bac5 --- /dev/null +++ b/window/wwalloc.c @@ -0,0 +1,82 @@ +/* $NetBSD: wwalloc.c,v 1.4 1997/11/21 08:36:57 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwalloc.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwalloc.c,v 1.4 1997/11/21 08:36:57 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "ww.h" + +char ** +wwalloc(row, col, nrow, ncol, size) + int row, col, nrow, ncol, size; +{ + char *p, **pp; + int i; + + /* fast, call malloc only once */ + pp = (char **) + malloc((unsigned) sizeof (char **) * nrow + size * nrow * ncol); + if (pp == 0) { + wwerrno = WWE_NOMEM; + return 0; + } + p = (char *)&pp[nrow]; + col *= size; + size /= sizeof (char); /* paranoid */ + size *= ncol; + for (i = 0; i < nrow; i++) { + pp[i] = p - col; + p += size; + } + return pp - row; +} + +void +wwfree(p, row) + char **p; + int row; +{ + free((char *)(p + row)); +} diff --git a/window/wwbox.c b/window/wwbox.c new file mode 100644 index 0000000..16c0dc5 --- /dev/null +++ b/window/wwbox.c @@ -0,0 +1,74 @@ +/* $NetBSD: wwbox.c,v 1.4 1997/11/21 08:36:58 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwbox.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwbox.c,v 1.4 1997/11/21 08:36:58 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +void +wwbox(w, r, c, nr, nc) + struct ww *w; + int r, c; + int nr, nc; +{ + int r1, c1; + int i; + + r1 = r + nr - 1; + c1 = c + nc - 1; + wwframec(w, r, c, WWF_D|WWF_R); + for (i = c + 1; i < c1; i++) + wwframec(w, r, i, WWF_L|WWF_R); + wwframec(w, r, i, WWF_L|WWF_D); + for (i = r + 1; i < r1; i++) + wwframec(w, i, c1, WWF_U|WWF_D); + wwframec(w, i, c1, WWF_U|WWF_L); + for (i = c1 - 1; i > c; i--) + wwframec(w, r1, i, WWF_R|WWF_L); + wwframec(w, r1, i, WWF_R|WWF_U); + for (i = r1 - 1; i > r; i--) + wwframec(w, i, c, WWF_D|WWF_U); +} diff --git a/window/wwchild.c b/window/wwchild.c new file mode 100644 index 0000000..53dfd7c --- /dev/null +++ b/window/wwchild.c @@ -0,0 +1,79 @@ +/* $NetBSD: wwchild.c,v 1.4 1997/11/21 08:37:00 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwchild.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwchild.c,v 1.4 1997/11/21 08:37:00 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include "ww.h" + +void +wwchild(dummy) + int dummy; +{ + int olderrno; + struct ww **wp; + union wait w; + int pid; + char collected = 0; + + olderrno = errno; + while ((pid = + wait3((int *)&w, WNOHANG|WUNTRACED, (struct rusage *)0)) > 0) { + for (wp = wwindex; wp < &wwindex[NWW]; wp++) { + if (*wp && (*wp)->ww_state == WWS_HASPROC + && (*wp)->ww_pid == pid) { + (*wp)->ww_state = WWS_DEAD; + collected = 1; + break; + } + } + } + errno = olderrno; + /* jump out of wwiomux when somebody dies */ + if (collected) + wwsetintr(); +} diff --git a/window/wwclose.c b/window/wwclose.c new file mode 100644 index 0000000..f316db2 --- /dev/null +++ b/window/wwclose.c @@ -0,0 +1,69 @@ +/* $NetBSD: wwclose.c,v 1.4 1997/11/21 08:37:01 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwclose.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwclose.c,v 1.4 1997/11/21 08:37:01 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "ww.h" + +void +wwclose(w) + struct ww *w; +{ + wwindex[w->ww_index] = 0; + if (w->ww_pty >= 0) + (void) close(w->ww_pty); + if (w->ww_socket >= 0) + (void) close(w->ww_socket); + wwfree((char **)w->ww_win, w->ww_w.t); + wwfree((char **)w->ww_buf, w->ww_b.t); + if (w->ww_fmap != 0) + wwfree((char **)w->ww_fmap, w->ww_w.t); + free((char *)(w->ww_nvis + w->ww_w.t)); + if (w->ww_ob != 0) + free(w->ww_ob); + free((char *)w); +} diff --git a/window/wwclreol.c b/window/wwclreol.c new file mode 100644 index 0000000..40ef777 --- /dev/null +++ b/window/wwclreol.c @@ -0,0 +1,104 @@ +/* $NetBSD: wwclreol.c,v 1.5 1997/11/21 08:37:03 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwclreol.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwclreol.c,v 1.5 1997/11/21 08:37:03 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +/* + * Clear w to the end of line. + * If cleared is true, then the screen line has already been cleared. + */ +void +wwclreol1(w, row, col, cleared) + struct ww *w; + int row, col; + char cleared; +{ + int i; + + /* + * Clear the buffer right off + */ + { + union ww_char *buf; + + buf = &w->ww_buf[row][col]; + for (i = w->ww_b.r - col; --i >= 0;) + buf++->c_w = ' '; + } + + /* + * If can't see it, just return. + */ + if (row < w->ww_i.t || row >= w->ww_i.b + || w->ww_i.r <= 0 || w->ww_i.r <= col) + return; + + if (col < w->ww_i.l) + col = w->ww_i.l; + + /* + * Now fix wwns. + */ + { + union ww_char *s; + unsigned char *smap; + char *win; + + i = col; + smap = &wwsmap[row][i]; + s = &wwns[row][i]; + win = &w->ww_win[row][i]; + for (i = w->ww_i.r - i; --i >= 0;) + if (*smap++ == w->ww_index) + s++->c_w = ' ' | *win++ << WWC_MSHIFT; + else + s++, win++; + } + if (!cleared) + wwtouched[row] |= WWU_TOUCHED; +} diff --git a/window/wwclreos.c b/window/wwclreos.c new file mode 100644 index 0000000..0059684 --- /dev/null +++ b/window/wwclreos.c @@ -0,0 +1,64 @@ +/* $NetBSD: wwclreos.c,v 1.5 1997/11/21 08:37:04 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwclreos.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwclreos.c,v 1.5 1997/11/21 08:37:04 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +void +wwclreos(w, row, col) + struct ww *w; + int row, col; +{ + int i; + + wwclreol(w, row, col); + for (i = row + 1; i < w->ww_b.b; i++) + wwclreol(w, i, w->ww_b.l); + /* XXX */ + if (!ISSET(w->ww_wflags, WWW_NOUPDATE)) + wwupdate1(w->ww_i.t, w->ww_i.b); +} diff --git a/window/wwcursor.c b/window/wwcursor.c new file mode 100644 index 0000000..3367449 --- /dev/null +++ b/window/wwcursor.c @@ -0,0 +1,103 @@ +/* $NetBSD: wwcursor.c,v 1.5 1997/11/21 08:37:06 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwcursor.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwcursor.c,v 1.5 1997/11/21 08:37:06 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +wwcursor(w, on) + struct ww *w; + int on; +{ + char *win; + + if (on) { + if (ISSET(w->ww_wflags, WWW_HASCURSOR)) + return; + SET(w->ww_wflags, WWW_HASCURSOR); + } else { + if (!ISSET(w->ww_wflags, WWW_HASCURSOR)) + return; + CLR(w->ww_wflags, WWW_HASCURSOR); + } + if (wwcursormodes != 0) { + win = &w->ww_win[w->ww_cur.r][w->ww_cur.c]; + *win ^= wwcursormodes; + if (w->ww_cur.r < w->ww_i.t || w->ww_cur.r >= w->ww_i.b + || w->ww_cur.c < w->ww_i.l || w->ww_cur.c >= w->ww_i.r) + return; + if (wwsmap[w->ww_cur.r][w->ww_cur.c] == w->ww_index) { + if (*win == 0) + w->ww_nvis[w->ww_cur.r]++; + else if (*win == wwcursormodes) + w->ww_nvis[w->ww_cur.r]--; + wwns[w->ww_cur.r][w->ww_cur.c].c_m ^= wwcursormodes; + wwtouched[w->ww_cur.r] |= WWU_TOUCHED; + } + } +} + +void +wwsetcursormodes(new) + int new; +{ + int i; + struct ww *w; + int old = wwcursormodes; + + new &= wwavailmodes; + if (new == wwcursormodes) + return; + for (i = 0; i < NWW; i++) + if (wwindex[i] != 0 && + ISSET((w = wwindex[i])->ww_wflags, WWW_HASCURSOR)) { + wwcursor(w, 0); + wwcursormodes = new; + wwcursor(w, 1); + wwcursormodes = old; + } + wwcursormodes = new; +} diff --git a/window/wwdata.c b/window/wwdata.c new file mode 100644 index 0000000..49b886a --- /dev/null +++ b/window/wwdata.c @@ -0,0 +1,46 @@ +/* $NetBSD: wwdata.c,v 1.4 1997/11/21 08:37:08 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdata.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwdata.c,v 1.4 1997/11/21 08:37:08 lukem Exp $"); +#endif +#endif /* not lint */ diff --git a/window/wwdelchar.c b/window/wwdelchar.c new file mode 100644 index 0000000..183b6ec --- /dev/null +++ b/window/wwdelchar.c @@ -0,0 +1,133 @@ +/* $NetBSD: wwdelchar.c,v 1.5 1997/11/21 08:37:10 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdelchar.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwdelchar.c,v 1.5 1997/11/21 08:37:10 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "xx.h" + +void +wwdelchar(w, row, col) + struct ww *w; + int row, col; +{ + int i; + int nvis; + + /* + * First, shift the line. + */ + { + union ww_char *p, *q; + + p = &w->ww_buf[row][col]; + q = p + 1; + for (i = w->ww_b.r - col; --i > 0;) + *p++ = *q++; + p->c_w = ' '; + } + + /* + * If can't see it, just return. + */ + if (row < w->ww_i.t || row >= w->ww_i.b + || w->ww_i.r <= 0 || w->ww_i.r <= col) + return; + + if (col < w->ww_i.l) + col = w->ww_i.l; + + /* + * Now find out how much is actually changed, and fix wwns. + */ + { + union ww_char *buf; + char *win; + union ww_char *ns; + unsigned char *smap; + char touched; + + nvis = 0; + smap = &wwsmap[row][col]; + for (i = col; i < w->ww_i.r && *smap++ != w->ww_index; i++) + ; + if (i >= w->ww_i.r) + return; + col = i; + buf = w->ww_buf[row]; + win = w->ww_win[row]; + ns = wwns[row]; + smap = &wwsmap[row][i]; + touched = wwtouched[row]; + for (; i < w->ww_i.r; i++) { + if (*smap++ != w->ww_index) + continue; + touched |= WWU_TOUCHED; + if (win[i]) + ns[i].c_w = + buf[i].c_w ^ win[i] << WWC_MSHIFT; + else { + nvis++; + ns[i] = buf[i]; + } + } + wwtouched[row] = touched; + } + + /* + * Can/Should we use delete character? + */ + if (tt.tt_delchar != 0 && nvis > (wwncol - col) / 2) { + union ww_char *p, *q; + + xxdelchar(row, col); + p = &wwos[row][col]; + q = p + 1; + for (i = wwncol - col; --i > 0;) + *p++ = *q++; + p->c_w = ' '; + } +} diff --git a/window/wwdelete.c b/window/wwdelete.c new file mode 100644 index 0000000..50d118d --- /dev/null +++ b/window/wwdelete.c @@ -0,0 +1,149 @@ +/* $NetBSD: wwdelete.c,v 1.5 1997/11/21 08:37:11 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdelete.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwdelete.c,v 1.5 1997/11/21 08:37:11 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +/* + * Pull w free from the cover list. + */ +void +wwdelete(w) + struct ww *w; +{ + int i; + + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + int j; + unsigned char *smap = wwsmap[i]; + union ww_char *ns = wwns[i]; + int nchanged = 0; + + for (j = w->ww_i.l; j < w->ww_i.r; j++) + if (smap[j] == w->ww_index) { + smap[j] = WWX_NOBODY; + ns[j].c_w = ' '; + nchanged++; + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + } + + { + struct ww *wp; + + for (wp = w->ww_forw; wp != &wwhead; wp = wp->ww_forw) + wp->ww_order--; + } + + if (w->ww_forw != &wwhead) + wwdelete1(w->ww_forw, + w->ww_i.t, w->ww_i.b, w->ww_i.l, w->ww_i.r); + + w->ww_back->ww_forw = w->ww_forw; + w->ww_forw->ww_back = w->ww_back; + w->ww_forw = w->ww_back = 0; +} + +void +wwdelete1(w, t, b, l, r) + struct ww *w; + int t, b, l, r; +{ + int i; + int tt, bb, ll, rr; + char hasglass; + +again: + hasglass = 0; + tt = MAX(t, w->ww_i.t); + bb = MIN(b, w->ww_i.b); + ll = MAX(l, w->ww_i.l); + rr = MIN(r, w->ww_i.r); + if (tt >= bb || ll >= rr) { + if ((w = w->ww_forw) == &wwhead) + return; + goto again; + } + for (i = tt; i < bb; i++) { + int j; + unsigned char *smap = wwsmap[i]; + union ww_char *ns = wwns[i]; + char *win = w->ww_win[i]; + union ww_char *buf = w->ww_buf[i]; + int nvis = w->ww_nvis[i]; + int nchanged = 0; + + for (j = ll; j < rr; j++) { + if (smap[j] != WWX_NOBODY) + continue; + if (win[j] & WWM_GLS) { + hasglass = 1; + continue; + } + smap[j] = w->ww_index; + ns[j].c_w = buf[j].c_w ^ win[j] << WWC_MSHIFT; + nchanged++; + if (win[j] == 0) + nvis++; + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + w->ww_nvis[i] = nvis; + } + if ((w = w->ww_forw) == &wwhead) + return; + if (hasglass) + goto again; + if (tt > t) + wwdelete1(w, t, tt, l, r); + if (bb < b) + wwdelete1(w, bb, b, l, r); + if (ll > l) + wwdelete1(w, tt, bb, l, ll); + if (rr < r) + wwdelete1(w, tt, bb, rr, r); +} diff --git a/window/wwdelline.c b/window/wwdelline.c new file mode 100644 index 0000000..351c71f --- /dev/null +++ b/window/wwdelline.c @@ -0,0 +1,96 @@ +/* $NetBSD: wwdelline.c,v 1.4 1997/11/21 08:37:13 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdelline.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwdelline.c,v 1.4 1997/11/21 08:37:13 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +wwdelline(w, row) + struct ww *w; + int row; +{ + int i; + union ww_char **cpp, **cqq; + union ww_char *cp; + int row1, row2; + char deleted; + int visible; + + /* + * Scroll first. + */ + if ((row1 = row) < w->ww_i.t) { + row1 = w->ww_i.t; + } + if ((row2 = w->ww_b.b) > w->ww_i.b) { + row2 = w->ww_i.b; + visible = 0; + } else + visible = 1; + deleted = wwscroll1(w, row1, row2, 1, visible); + + /* + * Fix the buffer. + * But leave clearing the last line for wwclreol(). + */ + cpp = &w->ww_buf[row]; + cqq = cpp + 1; + cp = *cpp; + for (i = w->ww_b.b - row; --i > 0;) + *cpp++ = *cqq++; + *cpp = cp; + + /* + * Now clear the last line. + */ + if (visible) + wwclreol1(w, w->ww_b.b - 1, w->ww_b.l, deleted); + else { + cp += w->ww_b.l; + for (i = w->ww_b.nc; --i >= 0;) + cp++->c_w = ' '; + } +} diff --git a/window/wwdump.c b/window/wwdump.c new file mode 100644 index 0000000..ea24c68 --- /dev/null +++ b/window/wwdump.c @@ -0,0 +1,128 @@ +/* $NetBSD: wwdump.c,v 1.6 1997/11/21 08:37:14 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwdump.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwdump.c,v 1.6 1997/11/21 08:37:14 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "ww.h" +#include "tt.h" + +static char cmap[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +void +wwdumpwin(w) + struct ww *w; +{ + int i, j; + + tt.tt_nmodes = 0; + (*tt.tt_clear)(); + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + (*tt.tt_move)(i, w->ww_i.l); + for (j = w->ww_i.l; j < w->ww_i.r; j++) + (*tt.tt_putc)(w->ww_win[i][j] & WWM_GLS ? 'G' : ' '); + } +} + +void +wwdumpnvis(w) + struct ww *w; +{ + int i; + char buf[20]; + + tt.tt_nmodes = 0; + (*tt.tt_clear)(); + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + (*tt.tt_move)(i, w->ww_i.l); + (void) sprintf(buf, "%d", w->ww_nvis[i]); + (*tt.tt_write)(buf, strlen(buf)); + } +} + +void +wwdumpsmap() +{ + int i, j; + + tt.tt_nmodes = 0; + (*tt.tt_clear)(); + for (i = 0; i < wwnrow; i++) { + (*tt.tt_move)(i, 0); + for (j = 0; j < wwncol; j++) + (*tt.tt_putc)(cmap[wwsmap[i][j]]); + } +} + +void +wwdumpns() +{ + int i, j; + + (*tt.tt_clear)(); + for (i = 0; i < wwnrow; i++) { + (*tt.tt_move)(i, 0); + for (j = 0; j < wwncol; j++) { + tt.tt_nmodes = wwns[i][j].c_m & tt.tt_availmodes; + (*tt.tt_putc)(wwns[i][j].c_c); + } + } +} + +void +wwdumpos() +{ + int i, j; + + (*tt.tt_clear)(); + for (i = 0; i < wwnrow; i++) { + (*tt.tt_move)(i, 0); + for (j = 0; j < wwncol; j++) { + tt.tt_nmodes = wwos[i][j].c_m & tt.tt_availmodes; + (*tt.tt_putc)(wwns[i][j].c_c); + } + } +} diff --git a/window/wwend.c b/window/wwend.c new file mode 100644 index 0000000..2431d70 --- /dev/null +++ b/window/wwend.c @@ -0,0 +1,75 @@ +/* $NetBSD: wwend.c,v 1.4 1997/11/21 08:37:16 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwend.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwend.c,v 1.4 1997/11/21 08:37:16 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "ww.h" +#include "tt.h" +#include "xx.h" + +void +wwend(exit) + int exit; +{ + if (tt.tt_checkpoint) { + (void) alarm(0); + wwdocheckpoint = 0; + } + xxend(); + (void) wwsettty(0, &wwoldtty); +#ifdef TERMINFO + if (exit) + wwterminfoend(); +#endif +} + +void +wwquit(dummy) + int dummy; +{ + wwend(1); + exit(1); +} diff --git a/window/wwenviron.c b/window/wwenviron.c new file mode 100644 index 0000000..d033e3d --- /dev/null +++ b/window/wwenviron.c @@ -0,0 +1,117 @@ +/* $NetBSD: wwenviron.c,v 1.5 1997/11/21 08:37:18 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwenviron.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwenviron.c,v 1.5 1997/11/21 08:37:18 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#if !defined(OLD_TTY) && !defined(TIOCSCTTY) && !defined(TIOCNOTTY) +#include +#endif +#include +#include +#include +#include +#include +#include "ww.h" + +/* + * Set up the environment of this process to run in window 'wp'. + */ +int +wwenviron(wp) + struct ww *wp; +{ + int i; +#ifndef TIOCSCTTY + int pgrp = getpid(); +#endif + char buf[1024]; + sigset_t sigset; + +#ifndef TIOCSCTTY + if ((i = open("/dev/tty", 0)) < 0) + goto bad; + if (ioctl(i, TIOCNOTTY, (char *)0) < 0) + goto bad; + (void) close(i); +#endif + if ((i = wp->ww_socket) < 0) { + if ((i = open(wp->ww_ttyname, 2)) < 0) + goto bad; + if (wwsettty(i, &wwwintty) < 0) + goto bad; + if (wwsetttysize(i, wp->ww_w.nr, wp->ww_w.nc) < 0) + goto bad; + } + (void) dup2(i, 0); + (void) dup2(i, 1); + (void) dup2(i, 2); + (void) close(i); +#ifdef TIOCSCTTY + (void) setsid(); + (void) ioctl(0, TIOCSCTTY, 0); +#else + (void) ioctl(0, TIOCSPGRP, (char *)&pgrp); + (void) setpgrp(pgrp, pgrp); +#endif + /* SIGPIPE is the only one we ignore */ + (void) signal(SIGPIPE, SIG_DFL); + sigemptyset(&sigset); + sigprocmask(SIG_SETMASK, &sigset, (sigset_t *)0); + /* + * Two conditions that make destructive setenv ok: + * 1. setenv() copies the string, + * 2. we've already called tgetent which copies the termcap entry. + */ + (void) sprintf(buf, "%sco#%d:li#%d:%s", + WWT_TERMCAP, wp->ww_w.nc, wp->ww_w.nr, wwwintermcap); + (void) setenv("TERMCAP", buf, 1); + (void) sprintf(buf, "%d", wp->ww_id + 1); + (void) setenv("WINDOW_ID", buf, 1); + return 0; +bad: + wwerrno = WWE_SYS; + return -1; +} diff --git a/window/wwerror.c b/window/wwerror.c new file mode 100644 index 0000000..ed20f09 --- /dev/null +++ b/window/wwerror.c @@ -0,0 +1,75 @@ +/* $NetBSD: wwerror.c,v 1.5 1998/07/26 15:28:20 mycroft Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwerror.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwerror.c,v 1.5 1998/07/26 15:28:20 mycroft Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "ww.h" + +const char * +wwerror() +{ + switch (wwerrno) { + case WWE_NOERR: + return "No error"; + case WWE_SYS: + return strerror(errno); + case WWE_NOMEM: + return "Out of memory"; + case WWE_TOOMANY: + return "Too many windows"; + case WWE_NOPTY: + return "Out of pseudo-terminals"; + case WWE_SIZE: + return "Bad window size"; + case WWE_BADTERM: + return "Unknown terminal type"; + case WWE_CANTDO: + return "Can't run window on this terminal"; + default: + return "Unknown error"; + } +} diff --git a/window/wwflush.c b/window/wwflush.c new file mode 100644 index 0000000..64dca64 --- /dev/null +++ b/window/wwflush.c @@ -0,0 +1,127 @@ +/* $NetBSD: wwflush.c,v 1.6 1997/11/21 08:37:21 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwflush.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwflush.c,v 1.6 1997/11/21 08:37:21 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include "ww.h" +#include "tt.h" +#include "xx.h" + +void +wwflush() +{ + int row, col; + + if ((row = wwcursorrow) < 0) + row = 0; + else if (row >= wwnrow) + row = wwnrow - 1; + if ((col = wwcursorcol) < 0) + col = 0; + else if (col >= wwncol) + col = wwncol - 1; + xxmove(row, col); + if (wwdocheckpoint) { + xxflush(0); + wwcheckpoint(); + } else + xxflush(1); +} + +void +wwcheckpoint() +{ + sigset_t sigset, osigset; + + sigemptyset(&sigset); + sigaddset(&sigset, SIGALRM); + sigprocmask(SIG_BLOCK, &sigset, &osigset); + + tt.tt_ack = 0; + do { + (*tt.tt_checkpoint)(); +#ifndef OLD_TTY + (void) tcdrain(1); +#endif + (void) alarm(3); + for (wwdocheckpoint = 0; !wwdocheckpoint && tt.tt_ack == 0;) + sigsuspend(&osigset); + } while (tt.tt_ack == 0); + (void) alarm(0); + wwdocheckpoint = 0; + if (tt.tt_ack < 0) { + wwcopyscreen(wwcs, wwos); + (void) alarm(1); + wwreset(); + wwupdate(); + wwflush(); + } else { + wwcopyscreen(wwos, wwcs); + (void) alarm(3); + } + + sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); +} + +void +wwcopyscreen(s1, s2) + union ww_char **s1, **s2; +{ + int i; + int s = wwncol * sizeof **s1; + + for (i = wwnrow; --i >= 0;) + memmove((char *) *s2++, (char *) *s1++, s); +} + +void +wwalarm(dummy) + int dummy; +{ + wwdocheckpoint = 1; +} diff --git a/window/wwframe.c b/window/wwframe.c new file mode 100644 index 0000000..13f0dfa --- /dev/null +++ b/window/wwframe.c @@ -0,0 +1,255 @@ +/* $NetBSD: wwframe.c,v 1.5 1997/11/21 08:37:22 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwframe.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwframe.c,v 1.5 1997/11/21 08:37:22 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" + +#define frameok(w, r, c) (w1 = wwindex[wwsmap[r][c]], \ + w1->ww_fmap || w1->ww_order > (w)->ww_order) + +void +wwframe(w, wframe) + struct ww *w; + struct ww *wframe; +{ + int r, c; + char a1, a2, a3; + char b1, b2, b3; + int code; + struct ww *w1; + + if (w->ww_w.t > 0) { + r = w->ww_w.t - 1; + c = w->ww_i.l - 1; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = c < 0 || frameok(w, r, c); + + for (; c < w->ww_i.r; c++) { + if (c + 1 >= wwncol) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == wwsmap[r + 1][c + 1]; + b3 = frameok(w, r, c + 1); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_L; + if ((a2 || a3) && b3) + code |= WWF_R; + if (code) + wwframec(wframe, r, c, code|WWF_TOP); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_L|WWF_TOP); + } + + if (w->ww_w.b < wwnrow) { + r = w->ww_w.b; + c = w->ww_i.l - 1; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = c < 0 || frameok(w, r, c); + + for (; c < w->ww_i.r; c++) { + if (c + 1 >= wwncol) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == wwsmap[r - 1][c + 1]; + b3 = frameok(w, r, c + 1); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_L; + if ((a2 || a3) && b3) + code |= WWF_R; + if (code) + wwframec(wframe, r, c, code); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_L); + } + + if (w->ww_w.l > 0) { + r = w->ww_i.t - 1; + c = w->ww_w.l - 1; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = r < 0 || frameok(w, r, c); + + for (; r < w->ww_i.b; r++) { + if (r + 1 >= wwnrow) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == wwsmap[r + 1][c + 1]; + b3 = frameok(w, r + 1, c); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_U; + if ((a2 || a3) && b3) + code |= WWF_D; + if (code) + wwframec(wframe, r, c, code); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_U); + } + + if (w->ww_w.r < wwncol) { + r = w->ww_i.t - 1; + c = w->ww_w.r; + a1 = 0; + a2 = 0; + b1 = 0; + b2 = r < 0 || frameok(w, r, c); + + for (; r < w->ww_i.b; r++) { + if (r + 1 >= wwnrow) { + a3 = 1; + b3 = 1; + } else { + a3 = w->ww_index == wwsmap[r + 1][c - 1]; + b3 = frameok(w, r + 1, c); + } + if (b2) { + code = 0; + if ((a1 || a2) && b1) + code |= WWF_U; + if ((a2 || a3) && b3) + code |= WWF_D; + if (code) + wwframec(wframe, r, c, code); + } + a1 = a2; + a2 = a3; + b1 = b2; + b2 = b3; + } + if ((a1 || a2) && b1 && b2) + wwframec(wframe, r, c, WWF_U); + } +} + +void +wwframec(f, r, c, code) + struct ww *f; + int r, c; + char code; +{ + char oldcode; + unsigned char *smap; + + if (r < f->ww_i.t || r >= f->ww_i.b || c < f->ww_i.l || c >= f->ww_i.r) + return; + + smap = &wwsmap[r][c]; + + { + struct ww *w; + + w = wwindex[*smap]; + if (w->ww_order > f->ww_order) { + if (w != &wwnobody && w->ww_win[r][c] == 0) + w->ww_nvis[r]--; + *smap = f->ww_index; + } + } + + if (f->ww_fmap != 0) { + char *fmap; + + fmap = &f->ww_fmap[r][c]; + oldcode = *fmap; + *fmap |= code; + if (code & WWF_TOP) + *fmap &= ~WWF_LABEL; + code = *fmap; + } else + oldcode = 0; + { + char *win = &f->ww_win[r][c]; + + if (*win == WWM_GLS && *smap == f->ww_index) + f->ww_nvis[r]++; + *win &= ~WWM_GLS; + } + if (oldcode != code && (code & WWF_LABEL) == 0) { + short frame; + + frame = tt.tt_frame[code & WWF_MASK]; + f->ww_buf[r][c].c_w = frame; + if (wwsmap[r][c] == f->ww_index) { + wwtouched[r] |= WWU_TOUCHED; + wwns[r][c].c_w = frame; + } + } +} diff --git a/window/wwgets.c b/window/wwgets.c new file mode 100644 index 0000000..ce0e9ea --- /dev/null +++ b/window/wwgets.c @@ -0,0 +1,120 @@ +/* $NetBSD: wwgets.c,v 1.7 1997/11/21 08:37:24 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwgets.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwgets.c,v 1.7 1997/11/21 08:37:24 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "ww.h" +#include "char.h" + +static void rub __P((int, struct ww *)); + +void +wwgets(buf, n, w) + char *buf; + int n; + struct ww *w; +{ + char *p = buf; + int c; + int uc = ISSET(w->ww_wflags, WWW_UNCTRL); + + CLR(w->ww_wflags, WWW_UNCTRL); + for (;;) { + wwcurtowin(w); + while ((c = wwgetc()) < 0) + wwiomux(); +#ifdef OLD_TTY + if (c == wwoldtty.ww_sgttyb.sg_erase) +#else + if (c == wwoldtty.ww_termios.c_cc[VERASE]) +#endif + { + if (p > buf) + rub(*--p, w); + } else +#ifdef OLD_TTY + if (c == wwoldtty.ww_sgttyb.sg_kill) +#else + if (c == wwoldtty.ww_termios.c_cc[VKILL]) +#endif + { + while (p > buf) + rub(*--p, w); + } else +#ifdef OLD_TTY + if (c == wwoldtty.ww_ltchars.t_werasc) +#else + if (c == wwoldtty.ww_termios.c_cc[VWERASE]) +#endif + { + while (--p >= buf && (*p == ' ' || *p == '\t')) + rub(*p, w); + while (p >= buf && *p != ' ' && *p != '\t') + rub(*p--, w); + p++; + } else if (c == '\r' || c == '\n') { + break; + } else { + if (p >= buf + n - 1) + wwputc(ctrl('g'), w); + else + wwputs(unctrl(*p++ = c), w); + } + } + *p = 0; + SET(w->ww_wflags, uc); +} + +static void +rub(c, w) + int c; + struct ww *w; +{ + int i; + + for (i = strlen(unctrl(c)); --i >= 0;) + (void) wwwrite(w, "\b \b", 3); +} diff --git a/window/wwinit.c b/window/wwinit.c new file mode 100644 index 0000000..bb8f505 --- /dev/null +++ b/window/wwinit.c @@ -0,0 +1,425 @@ +/* $NetBSD: wwinit.c,v 1.12 1997/11/21 08:37:26 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwinit.c 8.2 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: wwinit.c,v 1.12 1997/11/21 08:37:26 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#ifdef __APPLE__ +#include +#else +#include +#endif +#include "ww.h" +#include "tt.h" +#include "xx.h" +#include "char.h" + +int +wwinit() +{ + int i, j; + char *kp; + sigset_t sigset, osigset; + + wwdtablesize = 3; + wwhead.ww_forw = &wwhead; + wwhead.ww_back = &wwhead; + + sigemptyset(&sigset); + sigaddset(&sigset, SIGCHLD); + sigaddset(&sigset, SIGALRM); + sigaddset(&sigset, SIGHUP); + sigaddset(&sigset, SIGTERM); + sigprocmask(SIG_BLOCK, &sigset, &osigset); + + if (signal(SIGCHLD, wwchild) == BADSIG || + signal(SIGHUP, wwquit) == BADSIG || + signal(SIGTERM, wwquit) == BADSIG || + signal(SIGPIPE, SIG_IGN) == BADSIG) { + wwerrno = WWE_SYS; + return -1; + } + + if (wwgettty(0, &wwoldtty) < 0) + return -1; + wwwintty = wwoldtty; +#ifdef OLD_TTY + wwwintty.ww_sgttyb.sg_flags &= ~XTABS; + wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb; + wwnewtty.ww_sgttyb.sg_erase = -1; + wwnewtty.ww_sgttyb.sg_kill = -1; + wwnewtty.ww_sgttyb.sg_flags |= CBREAK; + wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD); + wwnewtty.ww_tchars.t_intrc = -1; + wwnewtty.ww_tchars.t_quitc = -1; + wwnewtty.ww_tchars.t_startc = -1; + wwnewtty.ww_tchars.t_stopc = -1; + wwnewtty.ww_tchars.t_eofc = -1; + wwnewtty.ww_tchars.t_brkc = -1; + wwnewtty.ww_ltchars.t_suspc = -1; + wwnewtty.ww_ltchars.t_dsuspc = -1; + wwnewtty.ww_ltchars.t_rprntc = -1; + wwnewtty.ww_ltchars.t_flushc = -1; + wwnewtty.ww_ltchars.t_werasc = -1; + wwnewtty.ww_ltchars.t_lnextc = -1; + wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT; + wwnewtty.ww_ldisc = wwoldtty.ww_ldisc; +#else +#ifndef OXTABS +#define OXTABS XTABS +#endif +#ifndef _POSIX_VDISABLE +#define _POSIX_VDISABLE -1 +#endif + wwwintty.ww_termios.c_oflag &= ~OXTABS; + wwnewtty.ww_termios = wwoldtty.ww_termios; + wwnewtty.ww_termios.c_iflag &= + ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL); + wwnewtty.ww_termios.c_oflag = 0; + wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB); + wwnewtty.ww_termios.c_cflag |= CS8; + wwnewtty.ww_termios.c_lflag = 0; + for (i = 0; i < NCCS; i++) + wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE; + wwnewtty.ww_termios.c_cc[VMIN] = 1; + wwnewtty.ww_termios.c_cc[VTIME] = 0; +#endif + if (wwsettty(0, &wwnewtty) < 0) + goto bad; + + if ((wwterm = getenv("TERM")) == 0) { + wwerrno = WWE_BADTERM; + goto bad; + } + if (tgetent(wwtermcap, wwterm) != 1) { + wwerrno = WWE_BADTERM; + goto bad; + } +#ifdef OLD_TTY + wwospeed = wwoldtty.ww_sgttyb.sg_ospeed; +#else + wwospeed = cfgetospeed(&wwoldtty.ww_termios); + wwbaud = wwospeed; +#endif + switch (wwospeed) { + default: + case B0: + wwbaud = 0; + break; + case B50: + wwbaud = 50; + break; + case B75: + wwbaud = 75; + break; + case B110: + wwbaud = 110; + break; + case B134: + wwbaud = 134; + break; + case B150: + wwbaud = 150; + break; + case B200: + wwbaud = 200; + break; + case B300: + wwbaud = 300; + break; + case B600: + wwbaud = 600; + break; + case B1200: + wwbaud = 1200; + break; + case B1800: + wwbaud = 1800; + break; + case B2400: + wwbaud = 2400; + break; + case B4800: + wwbaud = 4800; + break; + case B9600: + wwbaud = 9600; + break; +#ifdef B19200 + case B19200: +#else + case EXTA: +#endif + wwbaud = 19200; + break; +#ifdef B38400 + case B38400: +#else + case EXTB: +#endif + wwbaud = 38400; + break; +#ifdef B57600 + case B57600: + wwbaud= 57600; + break; +#endif +#ifdef B115200 + case B115200: + wwbaud = 115200; + break; +#endif + } + + if (xxinit() < 0) + goto bad; + wwnrow = tt.tt_nrow; + wwncol = tt.tt_ncol; + wwavailmodes = tt.tt_availmodes; + wwwrap = tt.tt_wrap; + + if (wwavailmodes & WWM_REV) + wwcursormodes = WWM_REV | (wwavailmodes & WWM_BLK); + else if (wwavailmodes & WWM_UL) + wwcursormodes = WWM_UL; + + if ((wwib = malloc((unsigned) 512)) == 0) + goto bad; + wwibe = wwib + 512; + wwibq = wwibp = wwib; + + wwsmap = (unsigned char **) + wwalloc(0, 0, wwnrow, wwncol, sizeof (unsigned char)); + if (wwsmap == 0) + goto bad; + for (i = 0; i < wwnrow; i++) + for (j = 0; j < wwncol; j++) + wwsmap[i][j] = WWX_NOBODY; + + wwos = (union ww_char **) + wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char)); + if (wwos == 0) + goto bad; + /* wwos is cleared in wwstart1() */ + wwns = (union ww_char **) + wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char)); + if (wwns == 0) + goto bad; + for (i = 0; i < wwnrow; i++) + for (j = 0; j < wwncol; j++) + wwns[i][j].c_w = ' '; + if (tt.tt_checkpoint) { + /* wwcs is also cleared in wwstart1() */ + wwcs = (union ww_char **) + wwalloc(0, 0, wwnrow, wwncol, sizeof (union ww_char)); + if (wwcs == 0) + goto bad; + } + + wwtouched = malloc((unsigned) wwnrow); + if (wwtouched == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + for (i = 0; i < wwnrow; i++) + wwtouched[i] = 0; + + wwupd = (struct ww_update *) malloc((unsigned) wwnrow * sizeof *wwupd); + if (wwupd == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + + wwindex[WWX_NOBODY] = &wwnobody; + wwnobody.ww_order = NWW; + + kp = wwwintermcap; + if (wwavailmodes & WWM_REV) + wwaddcap1(WWT_REV, &kp); + if (wwavailmodes & WWM_BLK) + wwaddcap1(WWT_BLK, &kp); + if (wwavailmodes & WWM_UL) + wwaddcap1(WWT_UL, &kp); + if (wwavailmodes & WWM_GRP) + wwaddcap1(WWT_GRP, &kp); + if (wwavailmodes & WWM_DIM) + wwaddcap1(WWT_DIM, &kp); + if (wwavailmodes & WWM_USR) + wwaddcap1(WWT_USR, &kp); + if ((tt.tt_insline && tt.tt_delline) || tt.tt_setscroll) + wwaddcap1(WWT_ALDL, &kp); + if (tt.tt_inschar) + wwaddcap1(WWT_IMEI, &kp); + if (tt.tt_insspace) + wwaddcap1(WWT_IC, &kp); + if (tt.tt_delchar) + wwaddcap1(WWT_DC, &kp); + wwaddcap("kb", &kp); + wwaddcap("ku", &kp); + wwaddcap("kd", &kp); + wwaddcap("kl", &kp); + wwaddcap("kr", &kp); + wwaddcap("kh", &kp); + if ((j = tgetnum("kn")) >= 0) { + char cap[32]; + + (void) sprintf(kp, "kn#%d:", j); + for (; *kp; kp++) + ; + for (i = 1; i <= j; i++) { + (void) sprintf(cap, "k%d", i); + wwaddcap(cap, &kp); + cap[0] = 'l'; + wwaddcap(cap, &kp); + } + } + /* + * It's ok to do this here even if setenv() is destructive + * since tt_init() has already made its own copy of it and + * wwterm now points to the copy. + */ + (void) setenv("TERM", WWT_TERM, 1); +#ifdef TERMINFO + if (wwterminfoinit() < 0) + goto bad; +#endif + + if (tt.tt_checkpoint) + if (signal(SIGALRM, wwalarm) == BADSIG) { + wwerrno = WWE_SYS; + goto bad; + } + wwstart1(); + + sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); + return 0; + +bad: + /* + * Don't bother to free storage. We're supposed + * to exit when wwinit fails anyway. + */ + (void) wwsettty(0, &wwoldtty); + + sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); + return -1; +} + +void +wwaddcap(cap, kp) + char *cap; + char **kp; +{ + char tbuf[512]; + char *tp = tbuf; + char *str, *p; + + if ((str = tgetstr(cap, &tp)) != 0) { + while ((*(*kp)++ = *cap++)) + ; + (*kp)[-1] = '='; + while (*str) { + for (p = unctrl(*str++); (*(*kp)++ = *p++);) + ; + (*kp)--; + } + *(*kp)++ = ':'; + **kp = 0; + } +} + +void +wwaddcap1(cap, kp) + char *cap; + char **kp; +{ + while ((*(*kp)++ = *cap++)) + ; + (*kp)--; +} + +void +wwstart() +{ + int i; + + (void) wwsettty(0, &wwnewtty); + for (i = 0; i < wwnrow; i++) + wwtouched[i] = WWU_TOUCHED; + wwstart1(); +} + +void +wwstart1() +{ + int i, j; + + for (i = 0; i < wwnrow; i++) + for (j = 0; j < wwncol; j++) { + wwos[i][j].c_w = ' '; + if (tt.tt_checkpoint) + wwcs[i][j].c_w = ' '; + } + xxstart(); + if (tt.tt_checkpoint) + wwdocheckpoint = 1; +} + +/* + * Reset data structures and terminal from an unknown state. + * Restoring wwos has been taken care of elsewhere. + */ +void +wwreset() +{ + int i; + + xxreset(); + for (i = 0; i < wwnrow; i++) + wwtouched[i] = WWU_TOUCHED; +} diff --git a/window/wwinschar.c b/window/wwinschar.c new file mode 100644 index 0000000..64a117c --- /dev/null +++ b/window/wwinschar.c @@ -0,0 +1,140 @@ +/* $NetBSD: wwinschar.c,v 1.5 1997/11/21 08:37:27 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwinschar.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwinschar.c,v 1.5 1997/11/21 08:37:27 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "xx.h" + +void +wwinschar(w, row, col, c, m) + struct ww *w; + int row, col; + char c, m; +{ + int i; + int nvis; + short x = c | m << WWC_MSHIFT; + + /* + * First, shift the line. + */ + { + union ww_char *p, *q; + + p = &w->ww_buf[row][w->ww_b.r]; + q = p - 1; + for (i = w->ww_b.r - col; --i > 0;) + *--p = *--q; + q->c_w = x; + } + + /* + * If can't see it, just return. + */ + if (row < w->ww_i.t || row >= w->ww_i.b + || w->ww_i.r <= 0 || w->ww_i.r <= col) + return; + + if (col < w->ww_i.l) + col = w->ww_i.l; + + /* + * Now find out how much is actually changed, and fix wwns. + */ + { + union ww_char *buf; + char *win; + union ww_char *ns; + unsigned char *smap; + char touched; + + nvis = 0; + smap = &wwsmap[row][col]; + for (i = col; i < w->ww_i.r && *smap++ != w->ww_index; i++) + ; + if (i >= w->ww_i.r) + return; + col = i; + buf = w->ww_buf[row]; + win = w->ww_win[row]; + ns = wwns[row]; + smap = &wwsmap[row][i]; + touched = wwtouched[row]; + for (; i < w->ww_i.r; i++) { + if (*smap++ != w->ww_index) + continue; + touched |= WWU_TOUCHED; + if (win[i]) + ns[i].c_w = + buf[i].c_w ^ win[i] << WWC_MSHIFT; + else { + nvis++; + ns[i] = buf[i]; + } + } + wwtouched[row] = touched; + } + + /* + * Can/Should we use delete character? + */ + if ((tt.tt_inschar || tt.tt_insspace) && nvis > (wwncol - col) / 2) { + union ww_char *p, *q; + + if (tt.tt_inschar) + xxinschar(row, col, c, m); + else { + xxinsspace(row, col); + x = ' '; + } + p = &wwos[row][wwncol]; + q = p - 1; + for (i = wwncol - col; --i > 0;) + *--p = *--q; + q->c_w = x; + } +} diff --git a/window/wwinsline.c b/window/wwinsline.c new file mode 100644 index 0000000..ba749f5 --- /dev/null +++ b/window/wwinsline.c @@ -0,0 +1,96 @@ +/* $NetBSD: wwinsline.c,v 1.4 1997/11/21 08:37:29 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwinsline.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwinsline.c,v 1.4 1997/11/21 08:37:29 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +wwinsline(w, row) + struct ww *w; + int row; +{ + int i; + union ww_char **cpp, **cqq; + union ww_char *cp; + int row1, row2; + char deleted; + int visible; + + /* + * Scroll first. + */ + if ((row1 = row) < w->ww_i.t) { + row1 = w->ww_i.t; + visible = 0; + } else + visible = 1; + if ((row2 = w->ww_b.b) > w->ww_i.b) { + row2 = w->ww_i.b; + } + deleted = wwscroll1(w, row1, row2, -1, visible); + + /* + * Fix the buffer. + * But leave clearing the last line for wwclreol(). + */ + cpp = &w->ww_buf[w->ww_b.b]; + cqq = cpp - 1; + cp = *cqq; + for (i = w->ww_b.b - row; --i > 0;) + *--cpp = *--cqq; + *cqq = cp; + + /* + * Now clear the last line. + */ + if (visible) + wwclreol1(w, row, w->ww_b.l, deleted); + else { + cp += w->ww_b.l; + for (i = w->ww_b.nc; --i >= 0;) + cp++->c_w = ' '; + } +} diff --git a/window/wwiomux.c b/window/wwiomux.c new file mode 100644 index 0000000..4bcc559 --- /dev/null +++ b/window/wwiomux.c @@ -0,0 +1,209 @@ +/* $NetBSD: wwiomux.c,v 1.6 1997/11/21 08:37:30 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwiomux.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwiomux.c,v 1.6 1997/11/21 08:37:30 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#if !defined(OLD_TTY) && !defined(TIOCPKT_DATA) +#include +#endif +#include +#include +#include +#include +#include "ww.h" + +/* + * Multiple window output handler. + * The idea is to copy window outputs to the terminal, via the + * display package. We try to give wwcurwin highest priority. + * The only return conditions are when there is keyboard input + * and when a child process dies. + * When there's nothing to do, we sleep in a select(). + * The history of this routine is interesting. + */ +void +wwiomux() +{ + struct ww *w; + fd_set imask; + volatile int n; + char *p; + char c; + struct timeval tv; + char noblock = 0; + + for (;;) { + if (wwinterrupt()) { + wwclrintr(); + return; + } + + FD_ZERO(&imask); + n = -1; + for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) { + if (w->ww_pty < 0) + continue; + if (w->ww_obq < w->ww_obe) { + if (w->ww_pty > n) + n = w->ww_pty + 1; + FD_SET(w->ww_pty, &imask); + } + if (w->ww_obq > w->ww_obp && + !ISSET(w->ww_pflags, WWP_STOPPED)) + noblock = 1; + } + if (wwibq < wwibe) { + if (0 > n) + n = 0 + 1; + FD_SET(0, &imask); + } + + if (!noblock) { + if (wwcurwin != 0) + wwcurtowin(wwcurwin); + wwupdate(); + wwflush(); + (void) setjmp(wwjmpbuf); + wwsetjmp = 1; + if (wwinterrupt()) { + wwsetjmp = 0; + wwclrintr(); + return; + } + /* XXXX */ + tv.tv_sec = 30; + tv.tv_usec = 0; + } else { + tv.tv_sec = 0; + tv.tv_usec = 10000; + } + wwnselect++; + n = select(n + 1, &imask, (fd_set *)0, (fd_set *)0, &tv); + wwsetjmp = 0; + noblock = 0; + + if (n < 0) + wwnselecte++; + else if (n == 0) + wwnselectz++; + else { + if (FD_ISSET(0, &imask)) + wwrint(); + for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) { + if (w->ww_pty < 0 || + !FD_ISSET(w->ww_pty, &imask)) + continue; + wwnwread++; + p = w->ww_obq; + if (w->ww_type == WWT_PTY) { + if (p == w->ww_ob) { + w->ww_obp++; + w->ww_obq++; + } else + p--; + c = *p; + } + n = read(w->ww_pty, p, w->ww_obe - p); + if (n < 0) { + wwnwreade++; + (void) close(w->ww_pty); + w->ww_pty = -1; + } else if (n == 0) { + wwnwreadz++; + (void) close(w->ww_pty); + w->ww_pty = -1; + } else if (w->ww_type != WWT_PTY) { + wwnwreadd++; + wwnwreadc += n; + w->ww_obq += n; + } else if (*p == TIOCPKT_DATA) { + n--; + wwnwreadd++; + wwnwreadc += n; + w->ww_obq += n; + } else { + wwnwreadp++; + if (*p & TIOCPKT_STOP) + SET(w->ww_pflags, WWP_STOPPED); + if (*p & TIOCPKT_START) + CLR(w->ww_pflags, WWP_STOPPED); + if (*p & TIOCPKT_FLUSHWRITE) { + CLR(w->ww_pflags, WWP_STOPPED); + w->ww_obq = w->ww_obp = + w->ww_ob; + } + } + } + } + /* + * Try the current window first, if there is output + * then process it and go back to the top to try again. + * This can lead to starvation of the other windows, + * but presumably that what we want. + * Update will eventually happen when output from wwcurwin + * dies down. + */ + if ((w = wwcurwin) != 0 && w->ww_pty >= 0 && + w->ww_obq > w->ww_obp && + !ISSET(w->ww_pflags, WWP_STOPPED)) { + n = wwwrite(w, w->ww_obp, w->ww_obq - w->ww_obp); + if ((w->ww_obp += n) == w->ww_obq) + w->ww_obq = w->ww_obp = w->ww_ob; + noblock = 1; + continue; + } + for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) + if (w->ww_pty >= 0 && w->ww_obq > w->ww_obp && + !ISSET(w->ww_pflags, WWP_STOPPED)) { + n = wwwrite(w, w->ww_obp, + w->ww_obq - w->ww_obp); + if ((w->ww_obp += n) == w->ww_obq) + w->ww_obq = w->ww_obp = w->ww_ob; + if (wwinterrupt()) + break; + } + } +} diff --git a/window/wwlabel.c b/window/wwlabel.c new file mode 100644 index 0000000..345a0f0 --- /dev/null +++ b/window/wwlabel.c @@ -0,0 +1,106 @@ +/* $NetBSD: wwlabel.c,v 1.5 1997/11/21 08:37:32 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwlabel.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwlabel.c,v 1.5 1997/11/21 08:37:32 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "char.h" + +/* + * Label window w on f, + * at 1 line above w and 'where' columns from it's left edge. + * Gross, but it works. + */ +void +wwlabel(w, f, where, l, mode) + struct ww *w; + struct ww *f; + int where; + char *l; + int mode; +{ + int row; + int j; + int jj; + char *win; + union ww_char *buf; + union ww_char *ns; + char *fmap; + unsigned char *smap; + char touched; + char *p; + + if (f->ww_fmap == 0) + return; + + row = w->ww_w.t - 1; + if (row < f->ww_i.t || row >= f->ww_i.b) + return; + win = f->ww_win[row]; + buf = f->ww_buf[row]; + fmap = f->ww_fmap[row]; + ns = wwns[row]; + smap = wwsmap[row]; + touched = wwtouched[row]; + mode <<= WWC_MSHIFT; + + jj = MIN(w->ww_i.r, f->ww_i.r); + j = w->ww_i.l + where; + while (j < jj && *l) + for (p = unctrl(*l++); j < jj && *p; j++, p++) { + /* can't label if not already framed */ + if (win[j] & WWM_GLS) + continue; + if (smap[j] != f->ww_index) + buf[j].c_w = mode | *p; + else { + ns[j].c_w = (buf[j].c_w = mode | *p) + ^ win[j] << WWC_MSHIFT; + touched |= WWU_TOUCHED; + } + fmap[j] |= WWF_LABEL; + } + wwtouched[row] = touched; +} diff --git a/window/wwmisc.c b/window/wwmisc.c new file mode 100644 index 0000000..cd74614 --- /dev/null +++ b/window/wwmisc.c @@ -0,0 +1,76 @@ +/* $NetBSD: wwmisc.c,v 1.5 1997/11/21 08:37:34 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwmisc.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwmisc.c,v 1.5 1997/11/21 08:37:34 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "char.h" + +/* + * Sufficient but not necessary test for total visibility. + */ +int +wwvisible(w) + struct ww *w; +{ + int i; + int nvis = 0; + + for (i = w->ww_i.t; i < w->ww_i.b; i++) + nvis += w->ww_nvis[i]; + if (ISSET(w->ww_wflags, WWW_HASCURSOR) + && w->ww_cur.r >= w->ww_i.t && w->ww_cur.r < w->ww_i.b + && w->ww_cur.c >= w->ww_i.l && w->ww_cur.c < w->ww_i.r + && wwsmap[w->ww_cur.r][w->ww_cur.c] == w->ww_index) + nvis++; + return nvis == w->ww_i.nr * w->ww_i.nc; +} + +void +wwbell() +{ + ttputc(ctrl('g')); +} diff --git a/window/wwmove.c b/window/wwmove.c new file mode 100644 index 0000000..23a5566 --- /dev/null +++ b/window/wwmove.c @@ -0,0 +1,107 @@ +/* $NetBSD: wwmove.c,v 1.5 1997/11/21 08:37:35 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwmove.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwmove.c,v 1.5 1997/11/21 08:37:35 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +/* + * Move a window. Should be unattached. + */ +void +wwmove(w, row, col) + struct ww *w; + int row, col; +{ + int dr, dc; + int i; + + dr = row - w->ww_w.t; + dc = col - w->ww_w.l; + + w->ww_w.t += dr; + w->ww_w.b += dr; + w->ww_w.l += dc; + w->ww_w.r += dc; + + w->ww_b.t += dr; + w->ww_b.b += dr; + w->ww_b.l += dc; + w->ww_b.r += dc; + + w->ww_i.t = MAX(w->ww_w.t, 0); + w->ww_i.b = MIN(w->ww_w.b, wwnrow); + w->ww_i.nr = w->ww_i.b - w->ww_i.t; + w->ww_i.l = MAX(w->ww_w.l, 0); + w->ww_i.r = MIN(w->ww_w.r, wwncol); + w->ww_i.nc = w->ww_i.r - w->ww_i.l; + + w->ww_cur.r += dr; + w->ww_cur.c += dc; + + w->ww_win -= dr; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_win[i] -= dc; + if (w->ww_fmap != 0) { + w->ww_fmap -= dr; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_fmap[i] -= dc; + } + w->ww_nvis -= dr; + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + int j = w->ww_i.l; + char *win = &w->ww_win[i][j]; + unsigned char *smap = &wwsmap[i][j]; + int nvis = 0; + + for (; j < w->ww_i.r; j++, win++, smap++) + if (*win == 0 && *smap == w->ww_index) + nvis++; + w->ww_nvis[i] = nvis; + } + w->ww_buf -= dr; + for (i = w->ww_b.t; i < w->ww_b.b; i++) + w->ww_buf[i] -= dc; +} diff --git a/window/wwopen.c b/window/wwopen.c new file mode 100644 index 0000000..9753cde --- /dev/null +++ b/window/wwopen.c @@ -0,0 +1,206 @@ +/* $NetBSD: wwopen.c,v 1.9 1998/08/25 20:59:43 ross Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwopen.c 8.2 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: wwopen.c,v 1.9 1998/08/25 20:59:43 ross Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include "ww.h" + +struct ww * +wwopen(type, oflags, nrow, ncol, row, col, nline) + int type, oflags, nrow, ncol, row, col, nline; +{ + struct ww *w; + int i, j; + char m; + short nvis; + + w = (struct ww *)calloc(sizeof (struct ww), 1); + if (w == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + w->ww_pty = -1; + w->ww_socket = -1; + + for (i = 0; i < NWW && wwindex[i] != 0; i++) + ; + if (i >= NWW) { + wwerrno = WWE_TOOMANY; + goto bad; + } + w->ww_index = i; + + if (nline < nrow) + nline = nrow; + + w->ww_w.t = row; + w->ww_w.b = row + nrow; + w->ww_w.l = col; + w->ww_w.r = col + ncol; + w->ww_w.nr = nrow; + w->ww_w.nc = ncol; + + w->ww_b.t = row; + w->ww_b.b = row + nline; + w->ww_b.l = col; + w->ww_b.r = col + ncol; + w->ww_b.nr = nline; + w->ww_b.nc = ncol; + + w->ww_i.t = MAX(w->ww_w.t, 0); + w->ww_i.b = MIN(w->ww_w.b, wwnrow); + w->ww_i.l = MAX(w->ww_w.l, 0); + w->ww_i.r = MIN(w->ww_w.r, wwncol); + w->ww_i.nr = w->ww_i.b - w->ww_i.t; + w->ww_i.nc = w->ww_i.r - w->ww_i.l; + + w->ww_cur.r = w->ww_w.t; + w->ww_cur.c = w->ww_w.l; + + w->ww_type = type; + switch (type) { + case WWT_PTY: + if (wwgetpty(w) < 0) + goto bad; + break; + case WWT_SOCKET: + { + int d[2]; + if (socketpair(AF_LOCAL, SOCK_STREAM, PF_UNSPEC, d) < 0) { + wwerrno = WWE_SYS; + goto bad; + } + (void) fcntl(d[0], F_SETFD, 1); + (void) fcntl(d[1], F_SETFD, 1); + w->ww_pty = d[0]; + w->ww_socket = d[1]; + break; + } + } + if (type != WWT_INTERNAL) { + if ((w->ww_ob = malloc(512)) == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + w->ww_obe = w->ww_ob + 512; + w->ww_obp = w->ww_obq = w->ww_ob; + if (w->ww_pty >= wwdtablesize) + wwdtablesize = w->ww_pty + 1; + } + + w->ww_win = wwalloc(w->ww_w.t, w->ww_w.l, + w->ww_w.nr, w->ww_w.nc, sizeof (char)); + if (w->ww_win == 0) + goto bad; + m = 0; + if (oflags & WWO_GLASS) + m |= WWM_GLS; + if (oflags & WWO_REVERSE) { + if (wwavailmodes & WWM_REV) + m |= WWM_REV; + else oflags &= ~WWO_REVERSE; + } + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_win[i][j] = m; + + if (oflags & WWO_FRAME) { + w->ww_fmap = wwalloc(w->ww_w.t, w->ww_w.l, + w->ww_w.nr, w->ww_w.nc, sizeof (char)); + if (w->ww_fmap == 0) + goto bad; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_fmap[i][j] = 0; + } + + w->ww_buf = (union ww_char **) + wwalloc(w->ww_b.t, w->ww_b.l, + w->ww_b.nr, w->ww_b.nc, sizeof (union ww_char)); + if (w->ww_buf == 0) + goto bad; + for (i = w->ww_b.t; i < w->ww_b.b; i++) + for (j = w->ww_b.l; j < w->ww_b.r; j++) + w->ww_buf[i][j].c_w = ' '; + + w->ww_nvis = (short *)malloc((unsigned) w->ww_w.nr * sizeof (short)); + if (w->ww_nvis == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + w->ww_nvis -= w->ww_w.t; + nvis = m ? 0 : w->ww_w.nc; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_nvis[i] = nvis; + + w->ww_state = WWS_INITIAL; + CLR(w->ww_oflags, WWO_ALLFLAGS); + SET(w->ww_oflags, oflags); + return wwindex[w->ww_index] = w; +bad: + if (w != 0) { + if (w->ww_win != 0) + wwfree(w->ww_win, w->ww_w.t); + if (w->ww_fmap != 0) + wwfree(w->ww_fmap, w->ww_w.t); + if (w->ww_buf != 0) + wwfree((char **)w->ww_buf, w->ww_b.t); + if (w->ww_nvis != 0) + free((char *)(w->ww_nvis + w->ww_w.t)); + if (w->ww_ob != 0) + free(w->ww_ob); + if (w->ww_pty >= 0) + (void) close(w->ww_pty); + if (w->ww_socket >= 0) + (void) close(w->ww_socket); + free((char *)w); + } + return 0; +} diff --git a/window/wwprintf.c b/window/wwprintf.c new file mode 100644 index 0000000..d93f1e5 --- /dev/null +++ b/window/wwprintf.c @@ -0,0 +1,80 @@ +/* $NetBSD: wwprintf.c,v 1.4 1997/11/21 08:37:38 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwprintf.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwprintf.c,v 1.4 1997/11/21 08:37:38 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +#if __STDC__ +wwprintf(struct ww *w, const char *fmt, ...) +#else +wwprintf(w, fmt, va_alist) + struct ww *w; + char *fmt; + va_dcl +#endif +{ + va_list ap; + +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + (void) wwvprintf(w, fmt, ap); + va_end(ap); +} + +void +wwvprintf(w, fmt, ap) + struct ww *w; + const char *fmt; + va_list ap; +{ + char buf[1024]; + + (void) wwwrite(w, buf, vsnprintf(buf, sizeof(buf), fmt, ap)); +} diff --git a/window/wwpty.c b/window/wwpty.c new file mode 100644 index 0000000..1b60204 --- /dev/null +++ b/window/wwpty.c @@ -0,0 +1,97 @@ +/* $NetBSD: wwpty.c,v 1.5 1997/11/21 08:49:12 mrg Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwpty.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwpty.c,v 1.5 1997/11/21 08:49:12 mrg Exp $"); +#endif +#endif /* not lint */ + +#if !defined(OLD_TTY) && !defined(TIOCPKT) +#include +#endif +#include +#include +#include +#include "ww.h" + +int +wwgetpty(w) + struct ww *w; +{ + char c, *p; + int tty; + int on = 1; +#define PTY "/dev/XtyXX" +#define _PT 5 +#define _PQRS 8 +#define _0_9 9 + + (void) strcpy(w->ww_ttyname, PTY); + for (c = 'p'; c <= 'u'; c++) { + w->ww_ttyname[_PT] = 'p'; + w->ww_ttyname[_PQRS] = c; + w->ww_ttyname[_0_9] = '0'; + if (access(w->ww_ttyname, 0) < 0) + break; + for (p = "0123456789abcdef"; *p; p++) { + w->ww_ttyname[_PT] = 'p'; + w->ww_ttyname[_0_9] = *p; + if ((w->ww_pty = open(w->ww_ttyname, 2)) < 0) + continue; + w->ww_ttyname[_PT] = 't'; + if ((tty = open(w->ww_ttyname, 2)) < 0) { + (void) close(w->ww_pty); + continue; + } + (void) close(tty); + if (ioctl(w->ww_pty, TIOCPKT, (char *)&on) < 0) { + (void) close(w->ww_pty); + continue; + } + (void) fcntl(w->ww_pty, F_SETFD, 1); + return 0; + } + } + w->ww_pty = -1; + wwerrno = WWE_NOPTY; + return -1; +} diff --git a/window/wwputc.c b/window/wwputc.c new file mode 100644 index 0000000..af7e578 --- /dev/null +++ b/window/wwputc.c @@ -0,0 +1,56 @@ +/* $NetBSD: wwputc.c,v 1.4 1997/11/21 08:37:41 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwputc.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwputc.c,v 1.4 1997/11/21 08:37:41 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +wwputc(c, w) + char c; + struct ww *w; +{ + (void) wwwrite(w, &c, sizeof c); +} diff --git a/window/wwputs.c b/window/wwputs.c new file mode 100644 index 0000000..793e15e --- /dev/null +++ b/window/wwputs.c @@ -0,0 +1,60 @@ +/* $NetBSD: wwputs.c,v 1.4 1997/11/21 08:37:43 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwputs.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwputs.c,v 1.4 1997/11/21 08:37:43 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +wwputs(s, w) + char *s; + struct ww *w; +{ + char *p = s; + + while (*p++) + ; + (void) wwwrite(w, s, p - s - 1); +} diff --git a/window/wwredraw.c b/window/wwredraw.c new file mode 100644 index 0000000..49bbc62 --- /dev/null +++ b/window/wwredraw.c @@ -0,0 +1,65 @@ +/* $NetBSD: wwredraw.c,v 1.4 1997/11/21 08:37:44 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwredraw.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwredraw.c,v 1.4 1997/11/21 08:37:44 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "xx.h" + +void +wwredraw() +{ + int i, j; + union ww_char *os; + + xxclear(); + for (i = 0; i < wwnrow; i++) { + wwtouched[i] = WWU_TOUCHED; + os = wwos[i]; + for (j = wwncol; --j >= 0;) + (os++)->c_w = ' '; + } +} diff --git a/window/wwredrawwin.c b/window/wwredrawwin.c new file mode 100644 index 0000000..7ed8d92 --- /dev/null +++ b/window/wwredrawwin.c @@ -0,0 +1,81 @@ +/* $NetBSD: wwredrawwin.c,v 1.5 1997/11/21 08:37:45 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwredrawwin.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwredrawwin.c,v 1.5 1997/11/21 08:37:45 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +wwredrawwin1(w, row1, row2, offset) + struct ww *w; + int row1, row2, offset; +{ + int row; + int col; + unsigned char *smap; + union ww_char *buf; + char *win; + union ww_char *ns; + int x; + int nchanged; + + for (row = row1; row < row2; row++) { + col = w->ww_i.l; + ns = wwns[row]; + smap = &wwsmap[row][col]; + buf = w->ww_buf[row + offset]; + win = w->ww_win[row]; + nchanged = 0; + for (; col < w->ww_i.r; col++) + if (*smap++ == w->ww_index && + ns[col].c_w != + (x = buf[col].c_w ^ win[col] << WWC_MSHIFT)) { + nchanged++; + ns[col].c_w = x; + } + if (nchanged > 0) + wwtouched[row] |= WWU_TOUCHED; + } +} diff --git a/window/wwrint.c b/window/wwrint.c new file mode 100644 index 0000000..929dc4a --- /dev/null +++ b/window/wwrint.c @@ -0,0 +1,87 @@ +/* $NetBSD: wwrint.c,v 1.5 1997/11/21 08:37:47 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwrint.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwrint.c,v 1.5 1997/11/21 08:37:47 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "ww.h" +#include "tt.h" + +/* + * Tty input interrupt handler. + * (1) Read input into buffer (wwib*). + * (2) Set the interrupt flag if anything is read. + * Currently, the last is used to get out of the blocking + * select() in wwiomux(). + * To avoid race conditions, we only modify wwibq in here, except + * when the buffer is empty; and everywhere else, we only change wwibp. + * It should be completely safe. + */ +void +wwrint() +{ + int n; + + wwnread++; + n = read(0, wwibq, wwibe - wwibq); + if (n > 0) { + if (tt.tt_rint) + n = (*tt.tt_rint)(wwibq, n); + if (n > 0) { + wwibq += n; + wwnreadc += n; + /* + * Hasten or delay the next checkpoint, + * as the case may be. + */ + if (tt.tt_checkpoint && !wwdocheckpoint) + (void) alarm(1); + wwsetintr(); + } + } else if (n == 0) + wwnreadz++; + else + wwnreade++; +} diff --git a/window/wwscroll.c b/window/wwscroll.c new file mode 100644 index 0000000..0ac8342 --- /dev/null +++ b/window/wwscroll.c @@ -0,0 +1,244 @@ +/* $NetBSD: wwscroll.c,v 1.4 1997/11/21 08:37:48 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwscroll.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwscroll.c,v 1.4 1997/11/21 08:37:48 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "xx.h" + +void +wwscroll(w, n) + struct ww *w; + int n; +{ + int dir; + int top; + + if (n == 0) + return; + dir = n < 0 ? -1 : 1; + top = w->ww_b.t - n; + if (top > w->ww_w.t) + top = w->ww_w.t; + else if (top + w->ww_b.nr < w->ww_w.b) + top = w->ww_w.b - w->ww_b.nr; + n = abs(top - w->ww_b.t); + if (n < w->ww_i.nr) { + while (--n >= 0) { + (void) wwscroll1(w, w->ww_i.t, w->ww_i.b, dir, 0); + w->ww_buf += dir; + w->ww_b.t -= dir; + w->ww_b.b -= dir; + } + } else { + w->ww_buf -= top - w->ww_b.t; + w->ww_b.t = top; + w->ww_b.b = top + w->ww_b.nr; + wwredrawwin(w); + } +} + +/* + * Scroll one line, between 'row1' and 'row2', in direction 'dir'. + * Don't adjust ww_scroll. + * And don't redraw 'leaveit' lines. + */ +int +wwscroll1(w, row1, row2, dir, leaveit) + struct ww *w; + int row1, row2, dir; + int leaveit; +{ + int i; + int row1x, row2x; + int nvis; + int nvismax; + int scrolled = 0; + + /* + * See how many lines on the screen are affected. + * And calculate row1x, row2x, and left at the same time. + */ + for (i = row1; i < row2 && w->ww_nvis[i] == 0; i++) + ; + if (i >= row2) /* can't do any fancy stuff */ + goto out; + row1x = i; + for (i = row2 - 1; i >= row1 && w->ww_nvis[i] == 0; i--) + ; + if (i <= row1x) + goto out; /* just one line is easy */ + row2x = i + 1; + + /* + * See how much of this window is visible. + */ + nvismax = wwncol * (row2x - row1x); + nvis = 0; + for (i = row1x; i < row2x; i++) + nvis += w->ww_nvis[i]; + + /* + * If it's a good idea to scroll and the terminal can, then do it. + */ + if (nvis < nvismax / 2) + goto no_scroll; /* not worth it */ + if ((dir > 0 ? tt.tt_scroll_down == 0 : tt.tt_scroll_up == 0) || + ((tt.tt_scroll_top != row1x || tt.tt_scroll_bot != row2x - 1) && + tt.tt_setscroll == 0)) + if (tt.tt_delline == 0 || tt.tt_insline == 0) + goto no_scroll; + xxscroll(dir, row1x, row2x); + scrolled = 1; + /* + * Fix up the old screen. + */ + { + union ww_char *tmp; + union ww_char **cpp, **cqq; + + if (dir > 0) { + cpp = &wwos[row1x]; + cqq = cpp + 1; + tmp = *cpp; + for (i = row2x - row1x; --i > 0;) + *cpp++ = *cqq++; + *cpp = tmp; + } else { + cpp = &wwos[row2x]; + cqq = cpp - 1; + tmp = *cqq; + for (i = row2x - row1x; --i > 0;) + *--cpp = *--cqq; + *cqq = tmp; + } + for (i = wwncol; --i >= 0;) + tmp++->c_w = ' '; + } + +no_scroll: + /* + * Fix the new screen. + */ + if (nvis == nvismax) { + /* + * Can shift whole lines. + */ + if (dir > 0) { + { + union ww_char *tmp; + union ww_char **cpp, **cqq; + + cpp = &wwns[row1x]; + cqq = cpp + 1; + tmp = *cpp; + for (i = row2x - row1x; --i > 0;) + *cpp++ = *cqq++; + *cpp = tmp; + } + if (scrolled) { + char *p, *q; + + p = &wwtouched[row1x]; + q = p + 1; + for (i = row2x - row1x; --i > 0;) + *p++ = *q++; + *p |= WWU_TOUCHED; + } else { + char *p; + + p = &wwtouched[row1x]; + for (i = row2x - row1x; --i >= 0;) + *p++ |= WWU_TOUCHED; + } + wwredrawwin1(w, row1, row1x, dir); + wwredrawwin1(w, row2x - 1, row2 - leaveit, dir); + } else { + { + union ww_char *tmp; + union ww_char **cpp, **cqq; + + cpp = &wwns[row2x]; + cqq = cpp - 1; + tmp = *cqq; + for (i = row2x - row1x; --i > 0;) + *--cpp = *--cqq; + *cqq = tmp; + } + if (scrolled) { + char *p, *q; + + p = &wwtouched[row2x]; + q = p - 1; + for (i = row2x - row1x; --i > 0;) + *--p = *--q; + *q |= WWU_TOUCHED; + } else { + char *p; + + p = &wwtouched[row1x]; + for (i = row2x - row1x; --i >= 0;) + *p++ |= WWU_TOUCHED; + } + wwredrawwin1(w, row1 + leaveit, row1x + 1, dir); + wwredrawwin1(w, row2x, row2, dir); + } + } else { + if (scrolled) { + char *p; + + p = &wwtouched[row1x]; + for (i = row2x - row1x; --i >= 0;) + *p++ |= WWU_TOUCHED; + } +out: + if (dir > 0) + wwredrawwin1(w, row1, row2 - leaveit, dir); + else + wwredrawwin1(w, row1 + leaveit, row2, dir); + } + return scrolled; +} diff --git a/window/wwsize.c b/window/wwsize.c new file mode 100644 index 0000000..1b146d7 --- /dev/null +++ b/window/wwsize.c @@ -0,0 +1,201 @@ +/* $NetBSD: wwsize.c,v 1.6 1997/11/21 08:37:49 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwsize.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwsize.c,v 1.6 1997/11/21 08:37:49 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "ww.h" + +/* + * Resize a window. Should be unattached. + */ +int +wwsize(w, nrow, ncol) + struct ww *w; + int nrow, ncol; +{ + int i, j; + int nline = 0; + union ww_char **buf = 0; + char **win = 0; + short *nvis = 0; + char **fmap = 0; + char m; + + /* + * First allocate new buffers. + */ + win = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char)); + if (win == 0) + goto bad; + if (w->ww_fmap != 0) { + fmap = wwalloc(w->ww_w.t, w->ww_w.l, nrow, ncol, sizeof (char)); + if (fmap == 0) + goto bad; + } + if (nrow > w->ww_b.nr || ncol > w->ww_b.nc) { + nline = MAX(w->ww_b.nr, nrow); + buf = (union ww_char **) wwalloc(w->ww_b.t, w->ww_b.l, + nline, ncol, sizeof (union ww_char)); + if (buf == 0) + goto bad; + } + nvis = (short *)malloc((unsigned) nrow * sizeof (short)); + if (nvis == 0) { + wwerrno = WWE_NOMEM; + goto bad; + } + nvis -= w->ww_w.t; + /* + * Copy text buffer. + */ + if (buf != 0) { + int b, r; + + b = w->ww_b.t + nline; + r = w->ww_b.l + ncol; + if (ncol < w->ww_b.nc) + for (i = w->ww_b.t; i < w->ww_b.b; i++) + for (j = w->ww_b.l; j < r; j++) + buf[i][j] = w->ww_buf[i][j]; + else + for (i = w->ww_b.t; i < w->ww_b.b; i++) { + for (j = w->ww_b.l; j < w->ww_b.r; j++) + buf[i][j] = w->ww_buf[i][j]; + for (; j < r; j++) + buf[i][j].c_w = ' '; + } + for (; i < b; i++) + for (j = w->ww_b.l; j < r; j++) + buf[i][j].c_w = ' '; + } + /* + * Now free the old stuff. + */ + wwfree((char **)w->ww_win, w->ww_w.t); + w->ww_win = win; + if (buf != 0) { + wwfree((char **)w->ww_buf, w->ww_b.t); + w->ww_buf = buf; + } + if (w->ww_fmap != 0) { + wwfree((char **)w->ww_fmap, w->ww_w.t); + w->ww_fmap = fmap; + } + free((char *)(w->ww_nvis + w->ww_w.t)); + w->ww_nvis = nvis; + /* + * Set new sizes. + */ + /* window */ + w->ww_w.b = w->ww_w.t + nrow; + w->ww_w.r = w->ww_w.l + ncol; + w->ww_w.nr = nrow; + w->ww_w.nc = ncol; + /* text buffer */ + if (buf != 0) { + w->ww_b.b = w->ww_b.t + nline; + w->ww_b.r = w->ww_b.l + ncol; + w->ww_b.nr = nline; + w->ww_b.nc = ncol; + } + /* scroll */ + if ((i = w->ww_b.b - w->ww_w.b) < 0 || + (i = w->ww_cur.r - w->ww_w.b + 1) > 0) { + w->ww_buf += i; + w->ww_b.t -= i; + w->ww_b.b -= i; + w->ww_cur.r -= i; + } + /* interior */ + w->ww_i.b = MIN(w->ww_w.b, wwnrow); + w->ww_i.r = MIN(w->ww_w.r, wwncol); + w->ww_i.nr = w->ww_i.b - w->ww_i.t; + w->ww_i.nc = w->ww_i.r - w->ww_i.l; + /* + * Initialize new buffers. + */ + /* window */ + m = 0; + if (w->ww_oflags & WWO_GLASS) + m |= WWM_GLS; + if (w->ww_oflags & WWO_REVERSE) + m |= WWM_REV; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_win[i][j] = m; + /* frame map */ + if (fmap != 0) + for (i = w->ww_w.t; i < w->ww_w.b; i++) + for (j = w->ww_w.l; j < w->ww_w.r; j++) + w->ww_fmap[i][j] = 0; + /* visibility */ + j = m ? 0 : w->ww_w.nc; + for (i = w->ww_w.t; i < w->ww_w.b; i++) + w->ww_nvis[i] = j; + /* + * Put cursor back. + */ + if (ISSET(w->ww_wflags, WWW_HASCURSOR)) { + CLR(w->ww_wflags, WWW_HASCURSOR); + wwcursor(w, 1); + } + /* + * Fool with pty. + */ + if (w->ww_type == WWT_PTY && w->ww_pty >= 0) + (void) wwsetttysize(w->ww_pty, nrow, ncol); + return 0; +bad: + if (win != 0) + wwfree(win, w->ww_w.t); + if (fmap != 0) + wwfree(fmap, w->ww_w.t); + if (buf != 0) + wwfree((char **)buf, w->ww_b.t); + if (nvis != 0) + free((char *)(nvis + w->ww_w.t)); + return -1; +} diff --git a/window/wwspawn.c b/window/wwspawn.c new file mode 100644 index 0000000..2fd6382 --- /dev/null +++ b/window/wwspawn.c @@ -0,0 +1,103 @@ +/* $NetBSD: wwspawn.c,v 1.6 1998/04/17 15:56:14 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwspawn.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwspawn.c,v 1.6 1998/04/17 15:56:14 cgd Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include "ww.h" + +/* + * There is a dead lock with vfork and closing of pseudo-ports. + * So we have to be sneaky about error reporting. + */ +int +wwspawn(wp, file, argv) + struct ww *wp; + char *file; + char **argv; +{ + int pid; + int ret; + char erred = 0; + sigset_t sigset, osigset; + +#ifdef __GNUC__ /* XXX variable `erred ' might be clobbered by ... `vfork' */ + (void)&erred; +#endif + + sigemptyset(&sigset); + sigaddset(&sigset, SIGCHLD); + sigprocmask(SIG_BLOCK, &sigset, &osigset); + + switch (pid = vfork()) { + case -1: + wwerrno = WWE_SYS; + ret = -1; + break; + case 0: + if (wwenviron(wp) >= 0) + execvp(file, argv); + erred = 1; + _exit(1); + default: + if (erred) { + wwerrno = WWE_SYS; + ret = -1; + } else { + wp->ww_pid = pid; + wp->ww_state = WWS_HASPROC; + ret = pid; + } + } + + sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); + + if (wp->ww_socket >= 0) { + (void) close(wp->ww_socket); + wp->ww_socket = -1; + } + return ret; +} diff --git a/window/wwsuspend.c b/window/wwsuspend.c new file mode 100644 index 0000000..10518b5 --- /dev/null +++ b/window/wwsuspend.c @@ -0,0 +1,64 @@ +/* $NetBSD: wwsuspend.c,v 1.4 1997/11/21 08:37:52 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwsuspend.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwsuspend.c,v 1.4 1997/11/21 08:37:52 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include "ww.h" +#include "tt.h" + +void +wwsuspend() +{ + sig_t oldsig; + + oldsig = signal(SIGTSTP, SIG_IGN); + wwend(0); + (void) signal(SIGTSTP, SIG_DFL); + (void) kill(0, SIGTSTP); + (void) signal(SIGTSTP, SIG_IGN); + wwstart(); + (void) signal(SIGTSTP, oldsig); +} diff --git a/window/wwterminfo.c b/window/wwterminfo.c new file mode 100644 index 0000000..10f9b37 --- /dev/null +++ b/window/wwterminfo.c @@ -0,0 +1,127 @@ +/* $NetBSD: wwterminfo.c,v 1.3 1997/12/31 06:56:04 thorpej Exp $ */ + +/* + * Copyright (c) 1982, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwterminfo.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwterminfo.c,v 1.3 1997/12/31 06:56:04 thorpej Exp $"); +#endif +#endif /* not lint */ + +#ifdef TERMINFO + +#include +#include +#include + +#include +#include +#include +#include +#include "local.h" +#include "ww.h" + +/* + * Terminfo support + * + * Written by Brian Buhrow + * + * Subsequently modified by Edward Wang + */ + +/* + * Initialize the working terminfo directory + */ +int +wwterminfoinit() +{ + FILE *fp; + char buf[2048]; + + /* make the directory */ + (void) sprintf(wwterminfopath, "%swwinXXXXXX", _PATH_TMP); + mktemp(wwterminfopath); + if (mkdir(wwterminfopath, 0755) < 0 || + chmod(wwterminfopath, 00755) < 0) { + wwerrno = WWE_SYS; + return -1; + } + (void) setenv("TERMINFO", wwterminfopath, 1); + /* make a termcap entry and turn it into terminfo */ + (void) sprintf(buf, "%s/cap", wwterminfopath); + if ((fp = fopen(buf, "w")) == NULL) { + wwerrno = WWE_SYS; + return -1; + } + (void) fprintf(fp, "%sco#%d:li#%d:%s\n", + WWT_TERMCAP, wwncol, wwnrow, wwwintermcap); + (void) fclose(fp); + (void) sprintf(buf, + "cd %s; %s cap >info 2>/dev/null; %s info >/dev/null 2>&1", + wwterminfopath, _PATH_CAPTOINFO, _PATH_TIC); + (void) system(buf); + return 0; +} + +/* + * Delete the working terminfo directory at shutdown + */ +int +wwterminfoend() +{ + int pstat; + pid_t pid; + + pid = vfork(); + switch (pid) { + case -1: + /* can't really do (or say) anything about errors */ + return -1; + case 0: + execl(_PATH_RM, _PATH_RM, "-rf", wwterminfopath, 0); + _exit(1); + } + pid = waitpid(pid, &pstat, 0); + if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0) + return -1; + return 0; +} + +#endif /* TERMINFO */ diff --git a/window/wwtty.c b/window/wwtty.c new file mode 100644 index 0000000..946b423 --- /dev/null +++ b/window/wwtty.c @@ -0,0 +1,195 @@ +/* $NetBSD: wwtty.c,v 1.5 1997/11/21 08:37:56 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwtty.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwtty.c,v 1.5 1997/11/21 08:37:56 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#if !defined(OLD_TTY) && !defined(TIOCGWINSZ) +#include +#endif +#include +#include "ww.h" + +int +wwgettty(d, t) + int d; + struct ww_tty *t; +{ +#ifdef OLD_TTY + if (ioctl(d, TIOCGETP, (char *)&t->ww_sgttyb) < 0) + goto bad; + if (ioctl(d, TIOCGETC, (char *)&t->ww_tchars) < 0) + goto bad; + if (ioctl(d, TIOCGLTC, (char *)&t->ww_ltchars) < 0) + goto bad; + if (ioctl(d, TIOCLGET, (char *)&t->ww_lmode) < 0) + goto bad; + if (ioctl(d, TIOCGETD, (char *)&t->ww_ldisc) < 0) + goto bad; +#else + if (tcgetattr(d, &t->ww_termios) < 0) + goto bad; +#endif + return 0; +bad: + wwerrno = WWE_SYS; + return -1; +} + +/* + * Set the modes of tty 'd' to 't' + * 'o' is the current modes. We set the line discipline only if + * it changes, to avoid unnecessary flushing of typeahead. + */ +int +wwsettty(d, t) + int d; + struct ww_tty *t; +{ +#ifdef OLD_TTY + int i; + + /* XXX, for buggy tty drivers that don't wait for output to drain */ + while (ioctl(d, TIOCOUTQ, &i) >= 0 && i > 0) + usleep(100000); + if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0) + goto bad; + if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0) + goto bad; + if (ioctl(d, TIOCSLTC, (char *)&t->ww_ltchars) < 0) + goto bad; + if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0) + goto bad; + if (ioctl(d, TIOCGETD, (char *)&i) < 0) + goto bad; + if (t->ww_ldisc != i && + ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0) + goto bad; +#else +#ifdef sun + /* XXX, for buggy tty drivers that don't wait for output to drain */ + (void) tcdrain(d); +#endif + if (tcsetattr(d, TCSADRAIN, &t->ww_termios) < 0) + goto bad; +#endif + return 0; +bad: + wwerrno = WWE_SYS; + return -1; +} + +/* + * The ttysize and stop-start routines must also work + * on the control side of pseudoterminals. + */ + +int +wwgetttysize(d, r, c) + int d; + int *r, *c; +{ + struct winsize winsize; + + if (ioctl(d, TIOCGWINSZ, (char *)&winsize) < 0) { + wwerrno = WWE_SYS; + return -1; + } + if (winsize.ws_row != 0) + *r = winsize.ws_row; + if (winsize.ws_col != 0) + *c = winsize.ws_col; + return 0; +} + +int +wwsetttysize(d, r, c) + int d, r, c; +{ + struct winsize winsize; + + winsize.ws_row = r; + winsize.ws_col = c; + winsize.ws_xpixel = winsize.ws_ypixel = 0; + if (ioctl(d, TIOCSWINSZ, (char *)&winsize) < 0) { + wwerrno = WWE_SYS; + return -1; + } + return 0; +} + +int +wwstoptty(d) + int d; +{ +#if !defined(OLD_TTY) && defined(TCOOFF) + /* not guaranteed to work on the pty side */ + if (tcflow(d, TCOOFF) < 0) +#else + if (ioctl(d, TIOCSTOP, (char *)0) < 0) +#endif + { + wwerrno = WWE_SYS; + return -1; + } + return 0; +} + +int +wwstarttty(d) + int d; +{ +#if !defined(OLD_TTY) && defined(TCOON) + /* not guaranteed to work on the pty side */ + if (tcflow(d, TCOON) < 0) +#else + if (ioctl(d, TIOCSTART, (char *)0) < 0) +#endif + { + wwerrno = WWE_SYS; + return -1; + } + return 0; +} diff --git a/window/wwunframe.c b/window/wwunframe.c new file mode 100644 index 0000000..f50de75 --- /dev/null +++ b/window/wwunframe.c @@ -0,0 +1,84 @@ +/* $NetBSD: wwunframe.c,v 1.5 1997/11/21 08:37:58 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwunframe.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwunframe.c,v 1.5 1997/11/21 08:37:58 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" + +void +wwunframe(w) + struct ww *w; +{ + int i; + + for (i = w->ww_i.t; i < w->ww_i.b; i++) { + int j; + char *win = w->ww_win[i]; + char *fmap = w->ww_fmap ? w->ww_fmap[i] : 0; + unsigned char *smap = wwsmap[i]; + union ww_char *ns = wwns[i]; + int nchanged = 0; + + for (j = w->ww_i.l; j < w->ww_i.r; j++) { + if (win[j] & WWM_GLS) + continue; + win[j] |= WWM_GLS; + if (fmap != 0) + fmap[j] = 0; + if (smap[j] == w->ww_index) { + smap[j] = WWX_NOBODY; + ns[j].c_w = ' '; + nchanged++; + } + } + if (nchanged > 0) + wwtouched[i] |= WWU_TOUCHED; + w->ww_nvis[i] = 0; + } + + if (w->ww_forw != &wwhead) + wwdelete1(w->ww_forw, + w->ww_i.t, w->ww_i.b, w->ww_i.l, w->ww_i.r); +} diff --git a/window/wwupdate.c b/window/wwupdate.c new file mode 100644 index 0000000..a1dbe7a --- /dev/null +++ b/window/wwupdate.c @@ -0,0 +1,281 @@ +/* $NetBSD: wwupdate.c,v 1.4 1997/11/21 08:37:59 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwupdate.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwupdate.c,v 1.4 1997/11/21 08:37:59 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "xx.h" + +void +wwupdate1(top, bot) + int top, bot; +{ + int i; + int j; + char *touched; + struct ww_update *upd; + char check_clreos = 0; + int scan_top, scan_bot; + + wwnupdate++; + { + char *t1 = wwtouched + top, *t2 = wwtouched + bot; + int n; + + while (!*t1++) + if (t1 == t2) + return; + while (!*--t2) + ; + scan_top = top = t1 - wwtouched - 1; + scan_bot = bot = t2 - wwtouched + 1; + if (scan_bot - scan_top > 1 && + (tt.tt_clreos != 0 || tt.tt_clear != 0)) { + int st = tt.tt_clreos != 0 ? scan_top : 0; + + /* + * t1 is one past the first touched row, + * t2 is on the last touched row. + */ + for (t1--, n = 1; t1 < t2;) + if (*t1++) + n++; + /* + * If we can't clreos then we try for clearing + * the whole screen. + */ + if ((check_clreos = n * 10 > (wwnrow - st) * 9)) { + scan_top = st; + scan_bot = wwnrow; + } + } + } + if (tt.tt_clreol == 0 && !check_clreos) + goto simple; + for (i = scan_top, touched = &wwtouched[i], upd = &wwupd[i]; + i < scan_bot; + i++, touched++, upd++) { + int gain = 0; + int best_gain = 0; + int best_col = 0; + union ww_char *ns, *os; + + if (wwinterrupt()) + return; + if (!check_clreos && !*touched) + continue; + wwnupdscan++; + j = wwncol; + ns = &wwns[i][j]; + os = &wwos[i][j]; + while (--j >= 0) { + /* + * The cost of clearing is: + * ncol - nblank + X + * The cost of straight update is, more or less: + * ncol - nsame + * We clear if nblank - nsame > X + * X is the clreol overhead. + * So we make gain = nblank - nsame. + */ + if ((--ns)->c_w == (--os)->c_w) + gain--; + else + best_gain--; + if (ns->c_w == ' ') + gain++; + if (gain > best_gain) { + best_col = j; + best_gain = gain; + } + } + upd->best_gain = best_gain; + upd->best_col = best_col; + upd->gain = gain; + } + if (check_clreos) { + struct ww_update *u; + int gain = 0; + int best_gain = 0; + int best_row = 0; + int simple_gain = 0; + char didit = 0; + + /* + * gain is the advantage of clearing all the lines. + * best_gain is the advantage of clearing to eos + * at best_row and u->best_col. + * simple_gain is the advantage of using only clreol. + * We use g > best_gain because u->best_col can be + * undefined when u->best_gain is 0 so we can't use it. + */ + for (j = scan_bot - 1, u = wwupd + j; j >= top; j--, u--) { + int g = gain + u->best_gain; + + if (g > best_gain) { + best_gain = g; + best_row = j; + } + gain += u->gain; + if (tt.tt_clreol != 0 && u->best_gain > 4) + simple_gain += u->best_gain - 4; + } + if (tt.tt_clreos == 0) { + if (gain > simple_gain && gain > 4) { + xxclear(); + i = top = scan_top; + bot = scan_bot; + j = 0; + didit = 1; + } + } else + if (best_gain > simple_gain && best_gain > 4) { + i = best_row; + xxclreos(i, j = wwupd[i].best_col); + bot = scan_bot; + didit = 1; + } + if (didit) { + wwnupdclreos++; + wwnupdclreosline += wwnrow - i; + u = wwupd + i; + while (i < scan_bot) { + union ww_char *os = &wwos[i][j]; + + for (j = wwncol - j; --j >= 0;) + os++->c_w = ' '; + wwtouched[i++] |= WWU_TOUCHED; + u++->best_gain = 0; + j = 0; + } + } else + wwnupdclreosmiss++; + } +simple: + for (i = top, touched = &wwtouched[i], upd = &wwupd[i]; i < bot; + i++, touched++, upd++) { + union ww_char *os, *ns; + char didit; + + if (!*touched) + continue; + *touched = 0; + wwnupdline++; + didit = 0; + if (tt.tt_clreol != 0 && upd->best_gain > 4) { + wwnupdclreol++; + xxclreol(i, j = upd->best_col); + for (os = &wwos[i][j], j = wwncol - j; --j >= 0;) + os++->c_w = ' '; + didit = 1; + } + ns = wwns[i]; + os = wwos[i]; + for (j = 0; j < wwncol;) { + char *p, *q; + char m; + int c; + int n; + char buf[512]; /* > wwncol */ + union ww_char lastc; + + for (; j++ < wwncol && ns++->c_w == os++->c_w;) + ; + if (j > wwncol) + break; + p = buf; + m = ns[-1].c_m; + c = j - 1; + os[-1] = ns[-1]; + *p++ = ns[-1].c_c; + n = 5; + q = p; + while (j < wwncol && ns->c_m == m) { + *p++ = ns->c_c; + if (ns->c_w == os->c_w) { + if (--n <= 0) + break; + os++; + ns++; + } else { + n = 5; + q = p; + lastc = *os; + *os++ = *ns++; + } + j++; + } + n = q - buf; + if (!wwwrap || i != wwnrow - 1 || c + n != wwncol) + xxwrite(i, c, buf, n, m); + else if (tt.tt_inschar || tt.tt_insspace) { + if (n > 1) { + q[-2] = q[-1]; + n--; + } else + c--; + xxwrite(i, c, buf, n, m); + c += n - 1; + if (tt.tt_inschar) + xxinschar(i, c, ns[-2].c_c, + ns[-2].c_m); + else { + xxinsspace(i, c); + xxwrite(i, c, &ns[-2].c_c, 1, + ns[-2].c_m); + } + } else { + if (--n) + xxwrite(i, c, buf, n, m); + os[-1] = lastc; + *touched = WWU_TOUCHED; + } + didit = 1; + } + if (!didit) + wwnupdmiss++; + } +} diff --git a/window/wwwrite.c b/window/wwwrite.c new file mode 100644 index 0000000..2ef9f9f --- /dev/null +++ b/window/wwwrite.c @@ -0,0 +1,313 @@ +/* $NetBSD: wwwrite.c,v 1.6 1997/11/21 08:38:00 lukem Exp $ */ + +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)wwwrite.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: wwwrite.c,v 1.6 1997/11/21 08:38:00 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "tt.h" +#include "xx.h" +#include "char.h" + +#define UPDATE() \ + if (!ISSET(w->ww_wflags, WWW_NOUPDATE) && w->ww_cur.r >= 0 && \ + w->ww_cur.r < wwnrow && wwtouched[w->ww_cur.r]) \ + wwupdate1(w->ww_cur.r, w->ww_cur.r + 1) + +/* + * To support control character expansion, we save the old + * p and q values in r and s, and point p at the beginning + * of the expanded string, and q at some safe place beyond it + * (p + 10). At strategic points in the loops, we check + * for (r && !*p) and restore the saved values back into + * p and q. Essentially, we implement a stack of depth 2, + * to avoid recursion, which might be a better idea. + */ +int +wwwrite(w, p, n) + struct ww *w; + char *p; + int n; +{ + int hascursor; + char *savep = p; + char *q = p + n; + char *r = 0; + char *s = 0; + +#ifdef lint + s = 0; /* define it before possible use */ +#endif + hascursor = ISSET(w->ww_wflags, WWW_HASCURSOR); + if (hascursor) + wwcursor(w, 0); + while (p < q && !ISSET(w->ww_pflags, WWP_STOPPED) && + (!wwinterrupt() || ISSET(w->ww_wflags, WWW_NOINTR))) { + if (r && !*p) { + p = r; + q = s; + r = 0; + continue; + } + if (w->ww_wstate == 0 && + (isprt(*p) || + (ISSET(w->ww_wflags, WWW_UNCTRL) && isunctrl(*p)))) { + int i; + union ww_char *bp; + int col, col1; + + if (ISSET(w->ww_wflags, WWW_INSERT)) { + /* this is very slow */ + if (*p == '\t') { + p++; + w->ww_cur.c += 8 - + ((w->ww_cur.c - w->ww_w.l) & 7); + goto chklf; + } + if (!isprt(*p)) { + r = p + 1; + s = q; + p = unctrl(*p); + q = p + 10; + } + wwinschar(w, w->ww_cur.r, w->ww_cur.c, + *p++, w->ww_modes); + goto right; + } + + bp = &w->ww_buf[w->ww_cur.r][w->ww_cur.c]; + i = w->ww_cur.c; + while (i < w->ww_w.r && p < q) + if (!*p && r) { + p = r; + q = s; + r = 0; + } else if (*p == '\t') { + int tmp = 8 - ((i - w->ww_w.l) & 7); + p++; + i += tmp; + bp += tmp; + } else if (isprt(*p)) { + bp++->c_w = *p++ + | w->ww_modes << WWC_MSHIFT; + i++; + } else if (ISSET(w->ww_wflags, WWW_UNCTRL) && + isunctrl(*p)) { + r = p + 1; + s = q; + p = unctrl(*p); + q = p + 10; + } else + break; + col = MAX(w->ww_cur.c, w->ww_i.l); + col1 = MIN(i, w->ww_i.r); + w->ww_cur.c = i; + if (w->ww_cur.r >= w->ww_i.t + && w->ww_cur.r < w->ww_i.b) { + union ww_char *ns = wwns[w->ww_cur.r]; + unsigned char *smap = + &wwsmap[w->ww_cur.r][col]; + char *win = w->ww_win[w->ww_cur.r]; + int nchanged = 0; + + bp = w->ww_buf[w->ww_cur.r]; + for (i = col; i < col1; i++) + if (*smap++ == w->ww_index) { + nchanged++; + ns[i].c_w = bp[i].c_w + ^ win[i] << WWC_MSHIFT; + } + if (nchanged > 0) + wwtouched[w->ww_cur.r] |= WWU_TOUCHED; + } + chklf: + if (w->ww_cur.c >= w->ww_w.r) + goto crlf; + } else switch (w->ww_wstate) { + case 0: + switch (*p++) { + case '\n': + if (ISSET(w->ww_wflags, WWW_MAPNL)) + crlf: + w->ww_cur.c = w->ww_w.l; + lf: + UPDATE(); + if (++w->ww_cur.r >= w->ww_w.b) { + w->ww_cur.r = w->ww_w.b - 1; + if (w->ww_w.b < w->ww_b.b) { + (void) wwscroll1(w, w->ww_i.t, + w->ww_i.b, 1, 0); + w->ww_buf++; + w->ww_b.t--; + w->ww_b.b--; + } else + wwdelline(w, w->ww_b.t); + } + break; + case '\b': + if (--w->ww_cur.c < w->ww_w.l) { + w->ww_cur.c = w->ww_w.r - 1; + goto up; + } + break; + case '\r': + w->ww_cur.c = w->ww_w.l; + break; + case ctrl('g'): + ttputc(ctrl('g')); + break; + case ctrl('['): + w->ww_wstate = 1; + break; + } + break; + case 1: + w->ww_wstate = 0; + switch (*p++) { + case '@': + SET(w->ww_wflags, WWW_INSERT); + break; + case 'A': + up: + UPDATE(); + if (--w->ww_cur.r < w->ww_w.t) { + w->ww_cur.r = w->ww_w.t; + if (w->ww_w.t > w->ww_b.t) { + (void) wwscroll1(w, w->ww_i.t, + w->ww_i.b, -1, 0); + w->ww_buf--; + w->ww_b.t++; + w->ww_b.b++; + } else + wwinsline(w, w->ww_b.t); + } + break; + case 'B': + goto lf; + case 'C': + right: + w->ww_cur.c++; + goto chklf; + case 'E': + w->ww_buf -= w->ww_w.t - w->ww_b.t; + w->ww_b.t = w->ww_w.t; + w->ww_b.b = w->ww_b.t + w->ww_b.nr; + w->ww_cur.r = w->ww_w.t; + w->ww_cur.c = w->ww_w.l; + wwclreos(w, w->ww_w.t, w->ww_w.l); + break; + case 'H': + UPDATE(); + w->ww_cur.r = w->ww_w.t; + w->ww_cur.c = w->ww_w.l; + break; + case 'J': + wwclreos(w, w->ww_cur.r, w->ww_cur.c); + break; + case 'K': + wwclreol(w, w->ww_cur.r, w->ww_cur.c); + break; + case 'L': + UPDATE(); + wwinsline(w, w->ww_cur.r); + break; + case 'M': + wwdelline(w, w->ww_cur.r); + break; + case 'N': + wwdelchar(w, w->ww_cur.r, w->ww_cur.c); + break; + case 'O': + CLR(w->ww_wflags, WWW_INSERT); + break; + case 'P': + wwinschar(w, w->ww_cur.r, w->ww_cur.c, ' ', 0); + break; + case 'X': + wwupdate(); + break; + case 'Y': + UPDATE(); + w->ww_wstate = 2; + break; + case 'Z': + wwupdate(); + xxflush(0); + break; + case 's': + w->ww_wstate = 4; + break; + case 'r': + w->ww_wstate = 5; + break; + } + break; + case 2: + w->ww_cur.r = w->ww_w.t + + (unsigned)(*p++ - ' ') % w->ww_w.nr; + w->ww_wstate = 3; + break; + case 3: + w->ww_cur.c = w->ww_w.l + + (unsigned)(*p++ - ' ') % w->ww_w.nc; + w->ww_wstate = 0; + break; + case 4: + w->ww_modes |= *p++ & wwavailmodes; + w->ww_wstate = 0; + break; + case 5: + w->ww_modes &= ~*p++; + w->ww_wstate = 0; + break; + } + } + if (hascursor) + wwcursor(w, 1); + wwnwwr++; + wwnwwra += n; + n = p - savep; + wwnwwrc += n; + return n; +} diff --git a/window/xx.c b/window/xx.c new file mode 100644 index 0000000..56459b6 --- /dev/null +++ b/window/xx.c @@ -0,0 +1,287 @@ +/* $NetBSD: xx.c,v 1.4 1997/11/21 08:38:02 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)xx.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: xx.c,v 1.4 1997/11/21 08:38:02 lukem Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#define EXTERN +#include "xx.h" +#undef EXTERN +#include "defs.h" +#include "tt.h" + +int +xxinit() +{ + if (ttinit() < 0) + return -1; + xxbufsize = tt.tt_nrow * tt.tt_ncol * 2; + /* ccinit may choose to change xxbufsize */ + if (tt.tt_ntoken > 0 && ccinit() < 0) + return -1; + xxbuf = malloc((unsigned) xxbufsize * sizeof *xxbuf); + if (xxbuf == 0) { + wwerrno = WWE_NOMEM; + return -1; + } + xxbufp = xxbuf; + xxbufe = xxbuf + xxbufsize; + return 0; +} + +void +xxstart() +{ + (*tt.tt_start)(); + if (tt.tt_ntoken > 0) + ccstart(); + xxreset1(); /* might be a restart */ +} + +void +xxreset() +{ + if (tt.tt_ntoken > 0) + ccreset(); + xxreset1(); + (*tt.tt_reset)(); +} + +void +xxreset1() +{ + struct xx *xp, *xq; + + for (xp = xx_head; xp != 0; xp = xq) { + xq = xp->link; + xxfree(xp); + } + xx_tail = xx_head = 0; + xxbufp = xxbuf; +} + +void +xxend() +{ + if (tt.tt_scroll_top != 0 || tt.tt_scroll_bot != tt.tt_nrow - 1) + /* tt.tt_setscroll is known to be defined */ + (*tt.tt_setscroll)(0, tt.tt_nrow - 1); + if (tt.tt_modes) + (*tt.tt_setmodes)(0); + if (tt.tt_scroll_down) + (*tt.tt_scroll_down)(1); + (*tt.tt_move)(tt.tt_nrow - 1, 0); + if (tt.tt_ntoken > 0) + ccend(); + (*tt.tt_end)(); + ttflush(); +} + +struct xx * +xxalloc() +{ + struct xx *xp; + + if (xxbufp > xxbufe) + abort(); + if ((xp = xx_freelist) == 0) + /* XXX can't deal with failure */ + xp = (struct xx *) malloc((unsigned) sizeof *xp); + else + xx_freelist = xp->link; + if (xx_head == 0) + xx_head = xp; + else + xx_tail->link = xp; + xx_tail = xp; + xp->link = 0; + return xp; +} + +void +xxfree(xp) + struct xx *xp; +{ + xp->link = xx_freelist; + xx_freelist = xp; +} + +void +xxmove(row, col) + int row, col; +{ + struct xx *xp = xx_tail; + + if (xp == 0 || xp->cmd != xc_move) { + xp = xxalloc(); + xp->cmd = xc_move; + } + xp->arg0 = row; + xp->arg1 = col; +} + +void +xxscroll(dir, top, bot) + int dir, top, bot; +{ + struct xx *xp = xx_tail; + + if (xp != 0 && xp->cmd == xc_scroll && + xp->arg1 == top && xp->arg2 == bot && + ((xp->arg0 < 0 && dir < 0) || (xp->arg0 > 0 && dir > 0))) { + xp->arg0 += dir; + return; + } + xp = xxalloc(); + xp->cmd = xc_scroll; + xp->arg0 = dir; + xp->arg1 = top; + xp->arg2 = bot; +} + +void +xxinschar(row, col, c, m) + int row, col, c, m; +{ + struct xx *xp; + + xp = xxalloc(); + xp->cmd = xc_inschar; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = c; + xp->arg3 = m; +} + +void +xxinsspace(row, col) + int row, col; +{ + struct xx *xp = xx_tail; + + if (xp != 0 && xp->cmd == xc_insspace && xp->arg0 == row && + col >= xp->arg1 && col <= xp->arg1 + xp->arg2) { + xp->arg2++; + return; + } + xp = xxalloc(); + xp->cmd = xc_insspace; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = 1; +} + +void +xxdelchar(row, col) + int row, col; +{ + struct xx *xp = xx_tail; + + if (xp != 0 && xp->cmd == xc_delchar && + xp->arg0 == row && xp->arg1 == col) { + xp->arg2++; + return; + } + xp = xxalloc(); + xp->cmd = xc_delchar; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = 1; +} + +void +xxclear() +{ + struct xx *xp; + + xxreset1(); + xp = xxalloc(); + xp->cmd = xc_clear; +} + +void +xxclreos(row, col) + int row, col; +{ + struct xx *xp = xxalloc(); + + xp->cmd = xc_clreos; + xp->arg0 = row; + xp->arg1 = col; +} + +void +xxclreol(row, col) + int row, col; +{ + struct xx *xp = xxalloc(); + + xp->cmd = xc_clreol; + xp->arg0 = row; + xp->arg1 = col; +} + +void +xxwrite(row, col, p, n, m) + int row, col; + char *p; + int n, m; +{ + struct xx *xp; + + if (xxbufp + n + 1 > xxbufe) + xxflush(0); + xp = xxalloc(); + xp->cmd = xc_write; + xp->arg0 = row; + xp->arg1 = col; + xp->arg2 = n; + xp->arg3 = m; + xp->buf = xxbufp; + memmove(xxbufp, p, n); + xxbufp += n; + *xxbufp++ = char_sep; +} diff --git a/window/xx.h b/window/xx.h new file mode 100644 index 0000000..56a0103 --- /dev/null +++ b/window/xx.h @@ -0,0 +1,81 @@ +/* $NetBSD: xx.h,v 1.4 1997/11/21 08:38:03 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)xx.h 8.1 (Berkeley) 6/6/93 + */ + +#ifndef EXTERN +#define EXTERN extern +#endif + +struct xx { + enum { xc_move, xc_scroll, xc_inschar, xc_insspace, xc_delchar, + xc_clear, xc_clreos, xc_clreol, xc_write } cmd; + int arg0; + int arg1; + int arg2; + int arg3; + char *buf; + struct xx *link; +}; + +EXTERN struct xx *xx_head, *xx_tail; +EXTERN struct xx *xx_freelist; + +EXTERN char *xxbuf, *xxbufp, *xxbufe; +EXTERN int xxbufsize; + +#define char_sep '\0' + +struct xx *xxalloc __P((void)); +void xxclear __P((void)); +void xxclreol __P((int, int)); +void xxclreos __P((int, int)); +void xxdelchar __P((int, int)); +void xxend __P((void)); +void xxflush __P((int)); +void xxflush_scroll __P((struct xx *)); +void xxfree __P((struct xx *)); +int xxinit __P((void)); +void xxinschar __P((int, int, int, int)); +void xxinsspace __P((int, int)); +void xxmove __P((int, int)); +void xxreset __P((void)); +void xxreset1 __P((void)); +void xxscroll __P((int, int, int)); +void xxstart __P((void)); +void xxwrite __P((int, int, char *, int, int)); diff --git a/window/xxflush.c b/window/xxflush.c new file mode 100644 index 0000000..41c8d65 --- /dev/null +++ b/window/xxflush.c @@ -0,0 +1,205 @@ +/* $NetBSD: xxflush.c,v 1.4 1997/11/21 08:38:05 lukem Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Edward Wang at The University of California, Berkeley. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)xxflush.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: xxflush.c,v 1.4 1997/11/21 08:38:05 lukem Exp $"); +#endif +#endif /* not lint */ + +#include "ww.h" +#include "xx.h" +#include "tt.h" + +void +xxflush(intr) + int intr; +{ + struct xx *xp, *xq; + + for (xp = xx_head; xp != 0 && !(intr && wwinterrupt()); xp = xq) { + switch (xp->cmd) { + case xc_move: + if (xp->link == 0) + (*tt.tt_move)(xp->arg0, xp->arg1); + break; + case xc_scroll: + xxflush_scroll(xp); + break; + case xc_inschar: + (*tt.tt_move)(xp->arg0, xp->arg1); + tt.tt_nmodes = xp->arg3; + (*tt.tt_inschar)(xp->arg2); + break; + case xc_insspace: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_insspace)(xp->arg2); + break; + case xc_delchar: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_delchar)(xp->arg2); + break; + case xc_clear: + (*tt.tt_clear)(); + break; + case xc_clreos: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_clreos)(); + break; + case xc_clreol: + (*tt.tt_move)(xp->arg0, xp->arg1); + (*tt.tt_clreol)(); + break; + case xc_write: + (*tt.tt_move)(xp->arg0, xp->arg1); + tt.tt_nmodes = xp->arg3; + (*tt.tt_write)(xp->buf, xp->arg2); + break; + } + xq = xp->link; + xxfree(xp); + } + if ((xx_head = xp) == 0) { + xx_tail = 0; + xxbufp = xxbuf; + } + ttflush(); +} + +void +xxflush_scroll(xp) + struct xx *xp; +{ + struct xx *xq; + + top: + if (xp->arg0 == 0) + return; + /* + * We handle retain (da and db) by putting the burden on scrolling up, + * which is the less common operation. It must ensure that + * text is not pushed below the screen, so scrolling down doesn't + * have to worry about it. + * + * Try scrolling region (or scrolling the whole screen) first. + * Can we assume "sr" doesn't push text below the screen + * so we don't have to worry about retain below? + * What about scrolling down with a newline? It probably does + * push text above (with da). Scrolling up would then have + * to take care of that. + * It's easy to be fool proof, but that slows things down. + * The current solution is to disallow tt_scroll_up if da or db is true + * but cs (scrolling region) is not. Again, we sacrifice scrolling + * up in favor of scrolling down. The idea is having scrolling regions + * probably means we can scroll (even the whole screen) with impunity. + * This lets us work efficiently on simple terminals (use newline + * on the bottom to scroll), on any terminal without retain, and + * on vt100 style scrolling regions (I think). + */ + if (xp->arg0 > 0) { + if ((xq = xp->link) != 0 && xq->cmd == xc_scroll && + xp->arg2 == xq->arg2 && xq->arg0 < 0) { + if (xp->arg1 < xq->arg1) { + if (xp->arg2 - xp->arg0 <= xq->arg1) { + xq->arg0 = xp->arg0; + xq->arg1 = xp->arg1; + xq->arg2 = xp->arg2; + return; + } + xp->arg2 = xq->arg1 + xp->arg0; + xq->arg0 += xp->arg0; + xq->arg1 = xp->arg2; + if (xq->arg0 > 0) + xq->arg1 -= xq->arg0; + goto top; + } else { + if (xp->arg1 - xq->arg0 >= xp->arg2) + return; + xq->arg2 = xp->arg1 - xq->arg0; + xp->arg0 += xq->arg0; + xp->arg1 = xq->arg2; + if (xp->arg0 < 0) + xp->arg1 += xp->arg0; + goto top; + } + } + if (xp->arg0 > xp->arg2 - xp->arg1) + xp->arg0 = xp->arg2 - xp->arg1; + if (tt.tt_scroll_down) { + if (tt.tt_scroll_top != xp->arg1 || + tt.tt_scroll_bot != xp->arg2 - 1) { + if (tt.tt_setscroll == 0) + goto down; + (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1); + } + tt.tt_scroll_down(xp->arg0); + } else { + down: + (*tt.tt_move)(xp->arg1, 0); + (*tt.tt_delline)(xp->arg0); + if (xp->arg2 < tt.tt_nrow) { + (*tt.tt_move)(xp->arg2 - xp->arg0, 0); + (*tt.tt_insline)(xp->arg0); + } + } + } else { + xp->arg0 = - xp->arg0; + if (xp->arg0 > xp->arg2 - xp->arg1) + xp->arg0 = xp->arg2 - xp->arg1; + if (tt.tt_scroll_up) { + if (tt.tt_scroll_top != xp->arg1 || + tt.tt_scroll_bot != xp->arg2 - 1) { + if (tt.tt_setscroll == 0) + goto up; + (*tt.tt_setscroll)(xp->arg1, xp->arg2 - 1); + } + tt.tt_scroll_up(xp->arg0); + } else { + up: + if (tt.tt_retain || xp->arg2 != tt.tt_nrow) { + (*tt.tt_move)(xp->arg2 - xp->arg0, 0); + (*tt.tt_delline)(xp->arg0); + } + (*tt.tt_move)(xp->arg1, 0); + (*tt.tt_insline)(xp->arg0); + } + } +} diff --git a/xargs/Makefile b/xargs/Makefile new file mode 100644 index 0000000..42b5920 --- /dev/null +++ b/xargs/Makefile @@ -0,0 +1,50 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = xargs + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +HFILES = pathnames.h + +CFILES = xargs.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble xargs.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/xargs/Makefile.postamble b/xargs/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/xargs/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/xargs/Makefile.preamble b/xargs/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/xargs/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/xargs/PB.project b/xargs/PB.project new file mode 100644 index 0000000..47a0e8c --- /dev/null +++ b/xargs/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (pathnames.h); + OTHER_LINKED = (xargs.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, xargs.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = xargs; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/xargs/pathnames.h b/xargs/pathnames.h new file mode 100644 index 0000000..ed4337b --- /dev/null +++ b/xargs/pathnames.h @@ -0,0 +1,38 @@ +/* $NetBSD: pathnames.h,v 1.4 1995/11/15 16:11:17 thorpej Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 + */ + +#define _PATH_ECHO "/bin/echo" diff --git a/xargs/xargs.1 b/xargs/xargs.1 new file mode 100644 index 0000000..cdff51a --- /dev/null +++ b/xargs/xargs.1 @@ -0,0 +1,192 @@ +.\" $NetBSD: xargs.1,v 1.7 1997/06/24 00:45:28 lukem Exp $ +.\" +.\" Copyright (c) 1990, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" John B. Roll Jr. and the Institute of Electrical and Electronics +.\" Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)xargs.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt XARGS 1 +.Os +.Sh NAME +.Nm xargs +.Nd "construct argument list(s) and execute utility" +.Sh SYNOPSIS +.Nm +.Op Fl 0 +.Op Fl t +.Oo Op Fl x +.Fl n Ar number +.Oc +.Op Fl s Ar size +.Op Ar utility Op Ar arguments ... +.Sh DESCRIPTION +The +.Nm +utility reads space, tab, newline and end-of-file delimited arguments +from the standard input and executes the specified +.Ar utility +with them as +arguments. +.Pp +The utility and any arguments specified on the command line are given +to the +.Ar utility +upon each invocation, followed by some number of the arguments read +from standard input. +The +.Ar utility +is repeatedly executed until standard input is exhausted. +.Pp +Spaces, tabs and newlines may be embedded in arguments using single +(``\ '\ '') +or double (``"'') quotes or backslashes (``\e''). +Single quotes escape all non-single quote characters, excluding newlines, +up to the matching single quote. +Double quotes escape all non-double quote characters, excluding newlines, +up to the matching double quote. +Any single character, including newlines, may be escaped by a backslash. +.Pp +The options are as follows: +.Bl -tag -width Fl +.It Fl 0 +Use NUL +(``\e0'') +instead of whitespace as the argument separator. +This can be used in conjuction with the +.Fl print0 +option of +.Xr find 1 . +.It Fl n Ar number +Set the maximum number of arguments taken from standard input for each +invocation of the utility. +An invocation of +.Ar utility +will use less than +.Ar number +standard input arguments if the number of bytes accumulated (see the +.Fl s +option) exceeds the specified +.Ar size +or there are fewer than +.Ar number +arguments remaining for the last invocation of +.Ar utility . +The current default value for +.Ar number +is 5000. +.It Fl s Ar size +Set the maximum number of bytes for the command line length provided to +.Ar utility . +The sum of the length of the utility name and the arguments passed to +.Ar utility +(including +.Dv NULL +terminators) will be less than or equal to this number. +The current default value for +.Ar size +is +.Dv ARG_MAX +- 2048. +.It Fl t +Echo the command to be executed to standard error immediately before it +is executed. +.It Fl x +Force +.Nm +to terminate immediately if a command line containing +.Ar number +arguments will not fit in the specified (or default) command line length. +.El +.Pp +If no +.Ar utility +is specified, +.Xr echo 1 +is used. +.Pp +Undefined behavior may occur if +.Ar utility +reads from the standard input. +.Pp +The +.Nm +utility exits immediately (without processing any further input) if a +command line cannot be assembled, +.Ar utility +cannot be invoked, an invocation of the utility is terminated by a signal +or an invocation of the utility exits with a value of 255. +.Sh DIAGNOSTICS +.Nm +exits with one of the following values: +.Bl -tag -width Ds -compact +.It 0 +All invocations of +.Ar utility +returned a zero exit status. +.It 123 +One or more invocations of +.Ar utility +returned a nonzero exit status. +.It 124 +The +.Ar utility +exited with a 255 exit status. +.It 125 +The +.Ar utility +was killed or stopped by a signal. +.It 126 +The +.Ar utility +was found but could not be invoked. +.It 127 +The +.Ar utility +could not be found. +.It 1 +Some other error occurred. +.El +.Sh SEE ALSO +.Xr echo 1 , +.Xr find 1 +.Sh STANDARDS +The +.Nm +utility is expected to be +.St -p1003.2 +compliant. +.Sh HISTORY +The meaning of 123, 124, and 125 exit values were taken from GNU xargs. diff --git a/xargs/xargs.c b/xargs/xargs.c new file mode 100644 index 0000000..81a0d9a --- /dev/null +++ b/xargs/xargs.c @@ -0,0 +1,344 @@ +/* $NetBSD: xargs.c,v 1.10 1998/04/14 09:26:33 fair Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * John B. Roll Jr. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: xargs.c,v 1.10 1998/04/14 09:26:33 fair Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "pathnames.h" + +int tflag, zflag, rval; + +void run __P((char **)); +int main __P((int, char **)); +void usage __P((void)); + +int +main(argc, argv) + int argc; + char **argv; +{ + int ch; + char *p, *bbp, *ebp, **bxp, **exp, **xp; + int cnt, indouble, insingle, nargs, nflag, nline, xflag; + char **av, *argp; + + setlocale(LC_ALL, ""); + + /* + * POSIX.2 limits the exec line length to ARG_MAX - 2K. Running that + * caused some E2BIG errors, so it was changed to ARG_MAX - 4K. Given + * that the smallest argument is 2 bytes in length, this means that + * the number of arguments is limited to: + * + * (ARG_MAX - 4K - LENGTH(utility + arguments)) / 2. + * + * We arbitrarily limit the number of arguments to 5000. This is + * allowed by POSIX.2 as long as the resulting minimum exec line is + * at least LINE_MAX. Realloc'ing as necessary is possible, but + * probably not worthwhile. + */ + nargs = 5000; + nline = ARG_MAX - 4 * 1024; + nflag = xflag = 0; + while ((ch = getopt(argc, argv, "0n:s:tx")) != -1) + switch(ch) { + case '0': + zflag = 1; + break; + case 'n': + nflag = 1; + if ((nargs = atoi(optarg)) <= 0) + errx(1, "illegal argument count"); + break; + case 's': + nline = atoi(optarg); + break; + case 't': + tflag = 1; + break; + case 'x': + xflag = 1; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (xflag && !nflag) + usage(); + + /* + * Allocate pointers for the utility name, the utility arguments, + * the maximum arguments to be read from stdin and the trailing + * NULL. + */ + if (!(av = bxp = + malloc((u_int)(1 + argc + nargs + 1) * sizeof(char **)))) + err(1, "malloc"); + + /* + * Use the user's name for the utility as argv[0], just like the + * shell. Echo is the default. Set up pointers for the user's + * arguments. + */ + if (!*argv) + cnt = strlen(*bxp++ = _PATH_ECHO); + else { + cnt = 0; + do { + cnt += strlen(*bxp++ = *argv) + 1; + } while (*++argv); + } + + /* + * Set up begin/end/traversing pointers into the array. The -n + * count doesn't include the trailing NULL pointer, so the malloc + * added in an extra slot. + */ + exp = (xp = bxp) + nargs; + + /* + * Allocate buffer space for the arguments read from stdin and the + * trailing NULL. Buffer space is defined as the default or specified + * space, minus the length of the utility name and arguments. Set up + * begin/end/traversing pointers into the array. The -s count does + * include the trailing NULL, so the malloc didn't add in an extra + * slot. + */ + nline -= cnt; + if (nline <= 0) + errx(1, "insufficient space for command"); + + if (!(bbp = malloc((u_int)nline + 1))) + err(1, "malloc"); + ebp = (argp = p = bbp) + nline - 1; + + for (insingle = indouble = 0;;) + switch(ch = getchar()) { + case EOF: + /* No arguments since last exec. */ + if (p == bbp) + exit(rval); + + /* Nothing since end of last argument. */ + if (argp == p) { + *xp = NULL; + run(av); + exit(rval); + } + goto arg1; + case ' ': + case '\t': + /* Quotes escape tabs and spaces. */ + if (insingle || indouble || zflag) + goto addch; + goto arg2; + case '\0': + if (zflag) + goto arg2; + goto addch; + case '\n': + if (zflag) + goto addch; + /* Empty lines are skipped. */ + if (argp == p) + continue; + + /* Quotes do not escape newlines. */ +arg1: if (insingle || indouble) + errx(1, "unterminated quote"); + +arg2: *p = '\0'; + *xp++ = argp; + + /* + * If max'd out on args or buffer, or reached EOF, + * run the command. If xflag and max'd out on buffer + * but not on args, object. + */ + if (xp == exp || p == ebp || ch == EOF) { + if (xflag && xp != exp && p == ebp) + errx(1, "insufficient space for arguments"); + *xp = NULL; + run(av); + if (ch == EOF) + exit(rval); + p = bbp; + xp = bxp; + } else + ++p; + argp = p; + break; + case '\'': + if (indouble || zflag) + goto addch; + insingle = !insingle; + break; + case '"': + if (insingle || zflag) + goto addch; + indouble = !indouble; + break; + case '\\': + if (zflag) + goto addch; + /* Backslash escapes anything, is escaped by quotes. */ + if (!insingle && !indouble && (ch = getchar()) == EOF) + errx(1, "backslash at EOF"); + /* FALLTHROUGH */ + default: +addch: if (p < ebp) { + *p++ = ch; + break; + } + + /* If only one argument, not enough buffer space. */ + if (bxp == xp) + errx(1, "insufficient space for argument"); + /* Didn't hit argument limit, so if xflag object. */ + if (xflag) + errx(1, "insufficient space for arguments"); + + *xp = NULL; + run(av); + xp = bxp; + cnt = ebp - argp; + memmove(bbp, argp, cnt); + p = (argp = bbp) + cnt; + *p++ = ch; + break; + } + /* NOTREACHED */ +} + +void +run(argv) + char **argv; +{ + volatile int noinvoke; + char **p; + pid_t pid; + int status; + + if (tflag) { + (void)fprintf(stderr, "%s", *argv); + for (p = argv + 1; *p; ++p) + (void)fprintf(stderr, " %s", *p); + (void)fprintf(stderr, "\n"); + (void)fflush(stderr); + } + noinvoke = 0; + switch(pid = vfork()) { + case -1: + err(1, "vfork"); + case 0: + execvp(argv[0], argv); + noinvoke = (errno == ENOENT) ? 127 : 126; + warn("%s", argv[0]);; + _exit(1); + } + pid = waitpid(pid, &status, 0); + if (pid == -1) + err(1, "waitpid"); + + /* + * If we couldn't invoke the utility or the utility didn't exit + * properly, quit with 127 or 126 respectively. + */ + if (noinvoke) + exit(noinvoke); + + /* + * According to POSIX, we have to exit if the utility exits with + * a 255 status, or is interrupted by a signal. xargs is allowed + * to return any exit status between 1 and 125 in these cases, but + * we'll use 124 and 125, the same values used by GNU xargs. + */ + if (WIFEXITED(status)) { + if (WEXITSTATUS (status) == 255) { + warnx ("%s exited with status 255", argv[0]); + exit(124); + } else if (WEXITSTATUS (status) != 0) { + rval = 123; + } + } else if (WIFSIGNALED (status)) { +#ifdef __APPLE__ + if (WTERMSIG(status) < NSIG) { +#else + if (WTERMSIG(status) < _NSIG) { +#endif + warnx("%s terminated by SIG%s", argv[0], + sys_signame[WTERMSIG(status)]); + } else { + warnx("%s terminated by signal %d", argv[0], + WTERMSIG(status)); + } + exit(125); + } +} + +void +usage() +{ + (void)fprintf(stderr, +"usage: xargs [-0t] [-n number [-x]] [-s size] [utility [argument ...]]\n"); + exit(1); +} diff --git a/yes/Makefile b/yes/Makefile new file mode 100644 index 0000000..ac96c28 --- /dev/null +++ b/yes/Makefile @@ -0,0 +1,48 @@ +# +# Generated by the NeXT Project Builder. +# +# NOTE: Do NOT change this file -- Project Builder maintains it. +# +# Put all of your customizations in files called Makefile.preamble +# and Makefile.postamble (both optional), and Makefile will include them. +# + +NAME = yes + +PROJECTVERSION = 2.8 +PROJECT_TYPE = Tool + +CFILES = yes.c + +OTHERSRCS = Makefile Makefile.preamble Makefile.postamble yes.1 + + +MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles +CODE_GEN_STYLE = DYNAMIC +MAKEFILE = tool.make +NEXTSTEP_INSTALLDIR = /usr/bin +LIBS = +DEBUG_LIBS = $(LIBS) +PROF_LIBS = $(LIBS) + + + + +NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build + +NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc +WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc +PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc +NEXTSTEP_JAVA_COMPILER = /usr/bin/javac +WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe +PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac + +include $(MAKEFILEDIR)/platform.make + +-include Makefile.preamble + +include $(MAKEFILEDIR)/$(MAKEFILE) + +-include Makefile.postamble + +-include Makefile.dependencies diff --git a/yes/Makefile.postamble b/yes/Makefile.postamble new file mode 100644 index 0000000..013b558 --- /dev/null +++ b/yes/Makefile.postamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/yes/Makefile.preamble b/yes/Makefile.preamble new file mode 100644 index 0000000..9e10e90 --- /dev/null +++ b/yes/Makefile.preamble @@ -0,0 +1 @@ +include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/yes/PB.project b/yes/PB.project new file mode 100644 index 0000000..7c91ca0 --- /dev/null +++ b/yes/PB.project @@ -0,0 +1,27 @@ +{ + DYNAMIC_CODE_GEN = YES; + FILESTABLE = { + FRAMEWORKS = (); + H_FILES = (); + OTHER_LINKED = (yes.c); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, yes.1); + SUBPROJECTS = (); + }; + LANGUAGE = English; + LOCALIZABLE_FILES = {}; + MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; + NEXTSTEP_BUILDDIR = "/tmp/$(NAME)/Build"; + NEXTSTEP_BUILDTOOL = /bin/gnumake; + NEXTSTEP_INSTALLDIR = /usr/bin; + NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; + NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; + PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; + PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; + PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; + PROJECTNAME = yes; + PROJECTTYPE = Tool; + PROJECTVERSION = 2.8; + WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; + WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; + WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; +} diff --git a/yes/yes.1 b/yes/yes.1 new file mode 100644 index 0000000..eab3795 --- /dev/null +++ b/yes/yes.1 @@ -0,0 +1,56 @@ +.\" $NetBSD: yes.1,v 1.4 1997/10/20 03:42:10 lukem Exp $ +.\" +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)yes.1 8.1 (Berkeley) 6/6/93 +.\" +.Dd June 6, 1993 +.Dt YES 1 +.Os BSD 4 +.Sh NAME +.Nm yes +.Nd be repetitively affirmative +.Sh SYNOPSIS +.Nm +.Op Ar expletive +.Sh DESCRIPTION +.Nm +outputs +.Ar expletive , +or, by default, +.Dq y , +forever. +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.0 . diff --git a/yes/yes.c b/yes/yes.c new file mode 100644 index 0000000..863f363 --- /dev/null +++ b/yes/yes.c @@ -0,0 +1,63 @@ +/* $NetBSD: yes.c,v 1.5 1997/10/19 14:28:27 mrg Exp $ */ + +/* + * Copyright (c) 1987, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)yes.c 8.1 (Berkeley) 6/6/93"; +#endif +__RCSID("$NetBSD: yes.c,v 1.5 1997/10/19 14:28:27 mrg Exp $"); +#endif /* not lint */ + +#include + +int main __P((int, char **)); + +int +main(argc, argv) + int argc; + char **argv; +{ + if (argc > 1) + for(;;) + (void)puts(argv[1]); + else for (;;) + (void)puts("y"); +} -- 2.45.2