From 9bafe2801c85cb98680afa22c908a5f5f018b3aa Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 24 Oct 2003 23:22:25 +0000 Subject: [PATCH] shell_cmds-53.tar.gz --- Makefile | 2 +- apply/apply.1 | 45 +- apply/apply.c | 140 +++-- basename/basename.1 | 56 +- basename/basename.c | 129 ++--- date/date.1 | 2 +- dirname/dirname.c | 103 +--- echo/echo.1 | 32 +- echo/echo.c | 49 +- env/env.c | 51 +- expr/expr.1 | 6 +- find/find.1 | 4 +- find/option.c | 4 +- getopt/getopt.1 | 95 ++-- getopt/getopt.c | 17 +- hostname/hostname.1 | 22 +- hostname/hostname.c | 39 +- id/groups.1 | 14 +- id/id.1 | 50 +- id/id.c | 181 +++--- id/whoami.1 | 14 +- jot/jot.1 | 138 +++-- jot/jot.c | 327 ++++++----- killall/killall.c | 77 ++- locate/locate/Makefile | 2 +- locate/locate/PB.project | 2 +- locate/locate/locate.updatedb.8 | 90 +++ locate/locate/updatedb.csh | 2 +- printf/printf.1 | 7 +- renice/renice.c | 2 +- su/su.c | 4 +- w/Makefile | 4 +- w/Makefile.postamble | 3 - w/extern.h | 18 +- w/fmt.c | 161 ++++-- w/pr_time.c | 75 +-- w/proc_compare.c | 22 +- w/uptime.1 | 7 +- w/w.1 | 30 +- w/w.c | 565 ++++++++++++------- which/which.1 | 4 +- 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 | 2 +- xargs/PB.project | 2 +- xargs/strnsubst.c | 99 ++++ xargs/xargs.1 | 191 +++++-- xargs/xargs.c | 552 +++++++++++++------ 151 files changed, 2177 insertions(+), 19267 deletions(-) create mode 100755 locate/locate/locate.updatedb.8 delete mode 100644 window/Makefile delete mode 100644 window/Makefile.postamble delete mode 100644 window/Makefile.preamble delete mode 100644 window/PB.project delete mode 100644 window/README delete mode 100644 window/alias.h delete mode 100644 window/char.c delete mode 100644 window/char.h delete mode 100644 window/cmd.c delete mode 100644 window/cmd1.c delete mode 100644 window/cmd2.c delete mode 100644 window/cmd3.c delete mode 100644 window/cmd4.c delete mode 100644 window/cmd5.c delete mode 100644 window/cmd6.c delete mode 100644 window/cmd7.c delete mode 100644 window/compress.c delete mode 100644 window/context.c delete mode 100644 window/context.h delete mode 100644 window/defs.h delete mode 100644 window/error.c delete mode 100644 window/lcmd.c delete mode 100644 window/lcmd.h delete mode 100644 window/lcmd1.c delete mode 100644 window/lcmd2.c delete mode 100644 window/local.h delete mode 100644 window/main.c delete mode 100644 window/mloop.c delete mode 100644 window/parser.h delete mode 100644 window/parser1.c delete mode 100644 window/parser2.c delete mode 100644 window/parser3.c delete mode 100644 window/parser4.c delete mode 100644 window/parser5.c delete mode 100644 window/scanner.c delete mode 100644 window/startup.c delete mode 100644 window/string.c delete mode 100644 window/token.h delete mode 100644 window/tt.h delete mode 100644 window/ttf100.c delete mode 100644 window/ttgeneric.c delete mode 100644 window/tth19.c delete mode 100644 window/tth29.c delete mode 100644 window/ttinit.c delete mode 100644 window/ttoutput.c delete mode 100644 window/tttermcap.c delete mode 100644 window/tttvi925.c delete mode 100644 window/ttwyse60.c delete mode 100644 window/ttwyse75.c delete mode 100644 window/ttzapple.c delete mode 100644 window/ttzentec.c delete mode 100644 window/value.h delete mode 100644 window/var.c delete mode 100644 window/var.h delete mode 100644 window/win.c delete mode 100644 window/window.1 delete mode 100644 window/window_string.h delete mode 100644 window/windowrc delete mode 100644 window/ww.h delete mode 100644 window/wwadd.c delete mode 100644 window/wwalloc.c delete mode 100644 window/wwbox.c delete mode 100644 window/wwchild.c delete mode 100644 window/wwclose.c delete mode 100644 window/wwclreol.c delete mode 100644 window/wwclreos.c delete mode 100644 window/wwcursor.c delete mode 100644 window/wwdata.c delete mode 100644 window/wwdelchar.c delete mode 100644 window/wwdelete.c delete mode 100644 window/wwdelline.c delete mode 100644 window/wwdump.c delete mode 100644 window/wwend.c delete mode 100644 window/wwenviron.c delete mode 100644 window/wwerror.c delete mode 100644 window/wwflush.c delete mode 100644 window/wwframe.c delete mode 100644 window/wwgets.c delete mode 100644 window/wwinit.c delete mode 100644 window/wwinschar.c delete mode 100644 window/wwinsline.c delete mode 100644 window/wwiomux.c delete mode 100644 window/wwlabel.c delete mode 100644 window/wwmisc.c delete mode 100644 window/wwmove.c delete mode 100644 window/wwopen.c delete mode 100644 window/wwprintf.c delete mode 100644 window/wwpty.c delete mode 100644 window/wwputc.c delete mode 100644 window/wwputs.c delete mode 100644 window/wwredraw.c delete mode 100644 window/wwredrawwin.c delete mode 100644 window/wwrint.c delete mode 100644 window/wwscroll.c delete mode 100644 window/wwsize.c delete mode 100644 window/wwspawn.c delete mode 100644 window/wwsuspend.c delete mode 100644 window/wwterminfo.c delete mode 100644 window/wwtty.c delete mode 100644 window/wwunframe.c delete mode 100644 window/wwupdate.c delete mode 100644 window/wwwrite.c delete mode 100644 window/xx.c delete mode 100644 window/xx.h delete mode 100644 window/xxflush.c create mode 100644 xargs/strnsubst.c diff --git a/Makefile b/Makefile index d6aa778..5975215 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ TOOLS = killall apply basename chroot date dirname echo env expr false\ find getopt hostname id jot kill lastcomm logname mktemp nice\ nohup printenv printf pwd renice script shlock sleep su\ tee test time true uname users w whereis which who\ - window xargs yes + xargs yes OTHERSRCS = PROJECT Makefile.preamble Makefile Makefile.postamble diff --git a/apply/apply.1 b/apply/apply.1 index da353b1..2eb1516 100644 --- a/apply/apply.1 +++ b/apply/apply.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -32,21 +30,24 @@ .\" SUCH DAMAGE. .\" .\" @(#)apply.1 8.2 (Berkeley) 4/4/94 +.\" $FreeBSD: src/usr.bin/apply/apply.1,v 1.14 2002/04/19 23:16:06 charnier Exp $ .\" .Dd April 4, 1994 .Dt APPLY 1 -.Os BSD 4.2 +.Os .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 # +.Op Fl a Ar c +.Op Fl d +.Op Fl # .Ar command argument ... .Sh DESCRIPTION +The .Nm -runs the named +utility runs the named .Ar command on each argument @@ -58,7 +59,7 @@ Character sequences of the form in .Ar command , where -.Dq Li d +.Sq Li d is a digit from 1 to 9, are replaced by the .Li d Ns \'th following unused @@ -68,8 +69,8 @@ each execution of .Ar command . .Pp The options are as follows: -.Bl -tag -width "-ac" -.It Fl Ns Ar # +.Bl -tag -width indent +.It Fl # Normally arguments are taken singly; the optional number .Fl # specifies the number of arguments to be passed to @@ -81,20 +82,24 @@ is run, without arguments, once for each .Pp If any sequences of .Dq Li \&%d -occur in command, the +occur in +.Ar command , +the .Fl # option is ignored. -.It Fl a Ns Ar c +.It Fl a Ar c The use of the character -.Dq Li % +.Sq Li % as a magic character may be changed with the .Fl a option. +.It Fl d +Display the commands that would have been executed, but do not actually +execute them. .El -.Sh ENVIRONMENT VARIABLES +.Sh ENVIRONMENT The following environment variable affects the execution of -.Nm -: +.Nm : .Bl -tag -width SHELL .It Ev SHELL Pathname of shell to use. @@ -115,13 +120,13 @@ runs links all files in the current directory to the directory .Pa /usr/joe . .El -.Sh Files +.Sh FILES .Bl -tag -width /bin/sh -compact .It Pa /bin/sh -Default shell +default shell .El -.Sh AUTHOR -Rob Pike +.Sh AUTHORS +.An Rob Pike .Sh BUGS Shell metacharacters in .Ar command @@ -131,5 +136,5 @@ commands in single quotes .Sh HISTORY The .Nm -command appeared in +command appeared in .Bx 4.2 . diff --git a/apply/apply.c b/apply/apply.c index 80379a0..cf4e9c1 100644 --- a/apply/apply.c +++ b/apply/apply.c @@ -1,5 +1,3 @@ -/* $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. @@ -36,15 +34,16 @@ * SUCH DAMAGE. */ -#include -#ifndef lint #if 0 +#ifndef lint 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 */ +#endif +#include +__RCSID("$FreeBSD: src/usr.bin/apply/apply.c,v 1.22 2002/07/14 18:22:12 alfred Exp $"); + +#include #include #include @@ -56,17 +55,16 @@ __RCSID("$NetBSD: apply.c,v 1.6 1997/12/31 05:53:45 thorpej Exp $"); #include #include -int main __P((int, char **)); -void usage __P((void)); -int system __P((const char *)); +#define EXEC "exec " + +static int exec_shell(const char *, char *, char *); +static void usage(void); int -main(argc, argv) - int argc; - char *argv[]; -{ - int ch, clen, debug, i, l, magic, n, nargs, rval; - char *c, *cmd, *p, *q; +main(int argc, char *argv[]) { + int ch, debug, i, magic, n, nargs, offset, rval; + size_t clen, cmdsize, l; + char *c, *cmd, *name, *p, *q, *shell, *slashp, *tmpshell; debug = 0; magic = '%'; /* Default magic char is `%'. */ @@ -76,7 +74,7 @@ main(argc, argv) case 'a': if (optarg[1] != '\0') errx(1, - "illegal magic character specification."); + "illegal magic character specification"); magic = optarg[0]; break; case 'd': @@ -86,7 +84,7 @@ main(argc, argv) case '5': case '6': case '7': case '8': case '9': if (nargs != -1) errx(1, - "only one -# argument may be specified."); + "only one -# argument may be specified"); nargs = optopt - '0'; break; default: @@ -110,25 +108,52 @@ main(argc, argv) n = p[0] - '0'; } + /* + * Figure out the shell and name arguments to pass to execl() + * in exec_shell(). Always malloc() shell and just set name + * to point at the last part of shell if there are any backslashes, + * otherwise just set it to point at the space malloc()'d. If + * SHELL environment variable exists, replace contents of + * shell with it. + */ + shell = name = NULL; + tmpshell = getenv("SHELL"); + shell = (tmpshell != NULL) ? strdup(tmpshell) : strdup(_PATH_BSHELL); + if (shell == NULL) + err(1, "strdup() failed"); + slashp = strrchr(shell, '/'); + name = (slashp != NULL) ? slashp + 1 : shell; + /* * 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. + * Allocate enough space to hold the maximum command. Save the + * size to pass to snprintf(). */ - if ((cmd = malloc(sizeof("exec ") - 1 + - strlen(argv[0]) + 9 * (sizeof(" %1") - 1) + 1)) == NULL) - err(1, "malloc"); - + cmdsize = sizeof(EXEC) - 1 + strlen(argv[0]) + + 9 * (sizeof(" %1") - 1) + 1; + if ((cmd = malloc(cmdsize)) == NULL) + err(1, NULL); + 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); + offset = snprintf(cmd, cmdsize, EXEC "%s", argv[0]); + if ((size_t)offset >= cmdsize) + err(1, "snprintf() failed"); + p += offset; + cmdsize -= offset; + for (i = 1; i <= nargs; i++) { + offset = snprintf(p, cmdsize, " %c%d", magic, i); + if ((size_t)offset >= cmdsize) + err(1, "snprintf() failed"); + p += offset; + cmdsize -= offset; + } /* * If nargs set to the special value 0, eat a single @@ -137,7 +162,9 @@ main(argc, argv) if (nargs == 0) nargs = 1; } else { - (void)sprintf(cmd, "exec %s", argv[0]); + offset = snprintf(cmd, cmdsize, EXEC "%s", argv[0]); + if ((size_t)offset >= cmdsize) + err(1, "snprintf() failed"); nargs = n; } @@ -147,7 +174,7 @@ main(argc, argv) * for the normal case. */ if ((c = malloc(clen = 1024)) == NULL) - err(1, "malloc"); + err(1, NULL); /* * (argc) and (argv) are still offset by one to make it simpler to @@ -160,15 +187,20 @@ main(argc, argv) * there's enough space to build it. */ for (l = strlen(cmd), i = 0; i < nargs; i++) - l += strlen(argv[i]); + l += strlen(argv[i+1]); if (l > clen && (c = realloc(c, clen = l)) == NULL) - err(1, "malloc"); + err(1, NULL); /* 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 + if (p[0] == magic && isdigit(p[1]) && p[1] != '0') { + offset = snprintf(q, l, "%s", + argv[(++p)[0] - '0']); + if ((size_t)offset >= l) + err(1, "snprintf() failed"); + q += offset; + l -= offset; + } else *q++ = *p; /* Terminate the command string. */ @@ -178,39 +210,31 @@ main(argc, argv) if (debug) (void)printf("%s\n", c); else - if (system(c)) + if (exec_shell(c, shell, name)) rval = 1; } if (argc != 1) errx(1, "expecting additional argument%s after \"%s\"", - (nargs - argc) ? "s" : "", argv[argc - 1]); + (nargs - argc) ? "s" : "", argv[argc - 1]); + free(cmd); + free(c); + free(shell); exit(rval); } /* - * system -- - * Private version of system(3). Use the user's SHELL environment - * variable as the shell to execute. + * exec_shell -- + * Execute a shell command using passed use_shell and use_name + * arguments. */ -int -system(command) - const char *command; +static int +exec_shell(const char *command, char *use_shell, char *use_name) { - static char *name, *shell; - union wait pstat; pid_t pid; - int omask; + int omask, pstat; 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); @@ -220,24 +244,24 @@ system(command) err(1, "vfork"); case 0: /* child */ (void)sigsetmask(omask); - execl(shell, name, "-c", command, NULL); - warn("%s", shell); + execl(use_shell, use_name, "-c", command, (char *)NULL); + warn("%s", use_shell); _exit(1); } intsave = signal(SIGINT, SIG_IGN); quitsave = signal(SIGQUIT, SIG_IGN); - pid = waitpid(pid, (int *)&pstat, 0); + pid = waitpid(pid, &pstat, 0); (void)sigsetmask(omask); (void)signal(SIGINT, intsave); (void)signal(SIGQUIT, quitsave); - return(pid == -1 ? -1 : pstat.w_status); + return(pid == -1 ? -1 : pstat); } void -usage() +usage(void) { (void)fprintf(stderr, - "usage: apply [-a magic] [-0123456789] command arguments ...\n"); + "usage: apply [-a magic] [-d] [-0123456789] command arguments ...\n"); exit(1); } diff --git a/basename/basename.1 b/basename/basename.1 index d2cf5b7..835d21a 100644 --- a/basename/basename.1 +++ b/basename/basename.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -35,53 +33,74 @@ .\" SUCH DAMAGE. .\" .\" @(#)basename.1 8.2 (Berkeley) 4/18/94 +.\" $FreeBSD: src/usr.bin/basename/basename.1,v 1.13 2002/06/30 13:40:35 jmallett Exp $ .\" .Dd April 18, 1994 .Dt BASENAME 1 .Os .Sh NAME -.Nm basename , -.Nm dirname +.Nm basename , dirname .Nd return filename or directory portion of pathname .Sh SYNOPSIS .Nm .Ar string .Op Ar suffix +.Nm +.Op Fl a +.Op Fl s Ar suffix +.Ar string +.Op Ar ... .Nm dirname .Ar string .Sh DESCRIPTION +The .Nm -deletes any prefix ending with the last slash +utility deletes any prefix ending with the last slash .Ql \&/ character present in -.Ar string , +.Ar string +(after first stripping trailing slashes), and a .Ar suffix , if given. +The +.Ar suffix +is not stripped if it is identical to the remaining characters in +.Ar string . The resulting filename is written to the standard output. A non-existent suffix is ignored. +If +.Fl a +is specified, then every argument is treated as a +.Ar string +as if +.Nm +were invoked with just one argument. +If +.Fl s +is specified, then the +.Ar suffix +is taken as its argument, and all other arguments are treated as a +.Ar string . .Pp +The .Nm dirname -deletes the filename portion, beginning +utility deletes the filename portion, beginning with the last slash .Ql \&/ character to the end of -.Ar string , +.Ar string +(after first stripping trailing slashes), and writes the result to the standard output. -.Sh EXAMPLES +.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 DIAGNOSTICS +.Ex -std basename dirname .Sh SEE ALSO .Xr csh 1 , .Xr sh 1 @@ -90,5 +109,6 @@ The .Nm and .Nm dirname -utilities conform to -.St -p1003.2-92 . +utilities are expected to be +.St -p1003.2 +compatible. diff --git a/basename/basename.c b/basename/basename.c index ac02aa1..6bde858 100644 --- a/basename/basename.c +++ b/basename/basename.c @@ -1,5 +1,3 @@ -/* $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. @@ -33,40 +31,49 @@ * 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 */ +static const char copyright[] = +"@(#) Copyright (c) 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif -#ifndef lint #if 0 +#ifndef lint 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 */ +#endif +#include +__RCSID("$FreeBSD: src/usr.bin/basename/basename.c,v 1.14 2002/09/04 23:28:52 dwmalone Exp $"); + +#include +#include #include #include #include -#include #include -int main __P((int, char **)); -void usage __P((void)); +void usage(void); int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { - char *p; - int ch; + char *p, *q, *suffix; + size_t suffixlen; + int aflag, ch; - setlocale(LC_ALL, ""); + aflag = 0; + suffix = NULL; + suffixlen = 0; - while ((ch = getopt(argc, argv, "")) != -1) + while ((ch = getopt(argc, argv, "as:")) != -1) switch(ch) { + case 'a': + aflag = 1; + break; + case 's': + suffix = optarg; + break; case '?': default: usage(); @@ -74,75 +81,39 @@ main(argc, argv) argc -= optind; argv += optind; - if (argc != 1 && argc != 2) + if (argc < 1) 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; + if (!*argv[0]) { + printf("\n"); + exit(0); } - - /* - * (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'; - } + if ((p = basename(argv[0])) == NULL) + err(1, "%s", argv[0]); + if ((suffix == NULL && !aflag) && argc == 2) { + suffix = argv[1]; + argc--; + } + if (suffix != NULL) + suffixlen = strlen(suffix); + while (argc--) { + if ((p = basename(*argv)) == NULL) + err(1, "%s", argv[0]); + if (suffixlen && (q = strchr(p, '\0') - suffixlen) > p && + strcmp(suffix, q) == 0) + *q = '\0'; + argv++; + (void)printf("%s\n", p); } - (void)printf("%s\n", p); exit(0); } void -usage() +usage(void) { - (void)fprintf(stderr, "usage: basename string [suffix]\n"); + (void)fprintf(stderr, +"usage: basename string [suffix]\n" +" basename [-a] [-s suffix] string [...]\n"); exit(1); } diff --git a/date/date.1 b/date/date.1 index 4fe9b53..a396b15 100644 --- a/date/date.1 +++ b/date/date.1 @@ -133,7 +133,7 @@ and years are handled automatically. .Sh EXAMPLES The command: .Bd -literal -offset indent -date ``+DATE: %m/%d/%y%nTIME: %H:%M:%S'' +date "+DATE: %m/%d/%y%nTIME: %H:%M:%S" .Ed .Pp will display: diff --git a/dirname/dirname.c b/dirname/dirname.c index 19f5b37..11b19b2 100644 --- a/dirname/dirname.c +++ b/dirname/dirname.c @@ -1,5 +1,3 @@ -/* $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. @@ -33,37 +31,32 @@ * SUCH DAMAGE. */ -#include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1991, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"); +static const char 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 $"); +static const char sccsid[] = "@(#)dirname.c 8.4 (Berkeley) 5/4/95"; #endif /* not lint */ +#include +__RCSID("$FreeBSD: src/usr.bin/dirname/dirname.c,v 1.11 2002/07/28 15:43:56 dwmalone Exp $"); +#include +#include #include #include -#include #include -int main __P((int, char **)); -static void usage __P((void)); +void usage(void); int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { - register char *p; + char *p; int ch; - setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "")) != -1) switch(ch) { case '?': @@ -76,80 +69,16 @@ main(argc, argv) 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); + if ((p = dirname(*argv)) == NULL) + err(1, "%s", *argv); + (void)printf("%s\n", p); exit(0); } -static void -usage() +void +usage(void) { (void)fprintf(stderr, "usage: dirname path\n"); exit(1); } - diff --git a/echo/echo.1 b/echo/echo.1 index e04e4cd..9e08e23 100644 --- a/echo/echo.1 +++ b/echo/echo.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -35,6 +33,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)echo.1 8.1 (Berkeley) 7/22/93 +.\" $FreeBSD: src/bin/echo/echo.1,v 1.13 2001/08/15 09:09:35 ru Exp $ .\" .Dd July 22, 1993 .Dt ECHO 1 @@ -45,25 +44,40 @@ .Sh SYNOPSIS .Nm .Op Fl n -.Op "string ..." +.Op Ar 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 +utility writes any specified operands, separated by single blank +.Pq Ql "\ " +characters and followed by a newline +.Pq Ql \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. +Do not print the trailing newline character. This may also be +achieved by appending +.Ql \ec +to the end of the string, as is done +by iBCS2 compatible systems. .El .Pp -The +Some shells may provide a builtin .Nm -utility exits 0 on success, and >0 if an error occurs. +command which is similar or identical to this utility. +Consult the +.Xr builtin 1 +manual page. +.Sh DIAGNOSTICS +.Ex -std .Sh SEE ALSO -.Xr printf 1 +.Xr builtin 1 , +.Xr csh 1 , +.Xr printf 1 , +.Xr sh 1 .Sh STANDARDS The .Nm diff --git a/echo/echo.c b/echo/echo.c index e427f46..bbb0539 100644 --- a/echo/echo.c +++ b/echo/echo.c @@ -1,5 +1,3 @@ -/* $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. @@ -33,34 +31,29 @@ * SUCH DAMAGE. */ -#include #ifndef lint -__COPYRIGHT( +static char const copyright[] = "@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\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 +__RCSID("$FreeBSD: src/bin/echo/echo.c,v 1.13 2002/06/30 05:13:53 obrien Exp $"); #include #include #include -int main __P((int, char *[])); - /* ARGSUSED */ int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { - int nflag; + int nflag; /* if not set, output a trailing newline. */ /* This utility may NOT do getopt(3) option parsing. */ if (*++argv && !strcmp(*argv, "-n")) { @@ -70,13 +63,31 @@ main(argc, argv) else nflag = 0; - while (*argv) { - (void)printf("%s", *argv); + while (argv[0] != NULL) { + + /* + * If the next argument is NULL then this is this + * the last argument, therefore we need to check + * for a trailing \c. + */ + if (argv[1] == NULL) { + size_t len; + + len = strlen(argv[0]); + /* is there room for a '\c' and is there one? */ + if (len >= 2 && + argv[0][len - 2] == '\\' && + argv[0][len - 1] == 'c') { + /* chop it and set the no-newline flag. */ + argv[0][len - 2] = '\0'; + nflag = 1; + } + } + (void)printf("%s", argv[0]); if (*++argv) - (void)putchar(' '); + putchar(' '); } if (!nflag) - (void)putchar('\n'); - exit(0); - /* NOTREACHED */ + putchar('\n'); + return 0; } diff --git a/env/env.c b/env/env.c index 42b7542..6aa4716 100644 --- a/env/env.c +++ b/env/env.c @@ -31,44 +31,42 @@ * SUCH DAMAGE. */ -#include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"); +static const char copyright[] = +"@(#) Copyright (c) 1988, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ +#if 0 #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 $"); +static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ +#endif + +#include +__RCSID("$FreeBSD: src/usr.bin/env/env.c,v 1.11 2002/09/04 23:28:59 dwmalone Exp $"); #include +#include #include #include #include #include -#include -#include -int main __P((int, char **)); -static void usage __P((void)); +extern char **environ; + +static void usage(void); int -main(argc, argv) - int argc; - char **argv; +main(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 */ + switch(ch) { + case '-': case 'i': environ = cleanenv; cleanenv[0] = NULL; @@ -77,28 +75,21 @@ main(argc, argv) 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 */ + err(errno == ENOENT ? 127 : 126, "%s", *argv); } - for (ep = environ; *ep; ep++) (void)printf("%s\n", *ep); - exit(0); } static void -usage () +usage(void) { - (void) fprintf(stderr, "usage: env [-i] [name=value ...] [command]\n"); - exit (1); + (void)fprintf(stderr, + "usage: env [-i] [name=value ...] [utility [argument ...]]\n"); + exit(1); } diff --git a/expr/expr.1 b/expr/expr.1 index c4f2280..ffc9015 100644 --- a/expr/expr.1 +++ b/expr/expr.1 @@ -50,7 +50,7 @@ Returns the results of addition or subtraction of integer-valued arguments. Returns the results of multiplication, integer division, or remainder of integer-valued arguments. .It Ar expr1 Li : Ar expr2 The -.Dq \: +.Dq \&: operator matches .Ar expr1 against @@ -58,6 +58,10 @@ against which must be a regular expression. The regular expression is anchored to the beginning of the string with an implicit .Dq ^ . +.Nm +expects "basic" regular expressions, see +.Xr re_format 7 +for more information on regular expressions. .Pp If the match succeeds and the pattern contains at least one regular expression subexpression diff --git a/find/find.1 b/find/find.1 index 5794024..5a3ad96 100644 --- a/find/find.1 +++ b/find/find.1 @@ -610,7 +610,9 @@ The operators are listed in order of decreasing precedence. This evaluates to true if the parenthesized expression evaluates to true. .Pp -.It Cm \&! Ar expression +.It Cm \&! Ar expression +.It Cm -false Ar expression +.It Cm -not Ar expression This is the unary .Tn NOT operator. diff --git a/find/option.c b/find/option.c index 7e73a5f..a0abc8b 100644 --- a/find/option.c +++ b/find/option.c @@ -72,6 +72,7 @@ static OPTION const options[] = { { "-empty", c_empty, f_empty, 0 }, { "-exec", c_exec, f_exec, 0 }, { "-execdir", c_exec, f_exec, F_EXECDIR }, + { "-false", c_simple, f_not, 0 }, { "-flags", c_flags, f_flags, 0 }, { "-follow", c_follow, f_always_true, 0 }, /* @@ -108,6 +109,7 @@ static OPTION const options[] = { { "-newermm", c_newer, f_newer, 0 }, { "-newermt", c_newer, f_newer, F_TIME2_T }, { "-nogroup", c_nogroup, f_nogroup, 0 }, + { "-not", c_simple, f_not, 0 }, { "-nouser", c_nouser, f_nouser, 0 }, { "-o", c_simple, f_or, 0 }, { "-ok", c_exec, f_exec, F_NEEDOK }, @@ -144,7 +146,7 @@ find_create(argvp) argv = *argvp; if ((p = option(*argv)) == NULL) - errx(1, "%s: unknown option", *argv); + errx(1, "%s: unknown expression primary", *argv); ++argv; new = (p->create)(p, &argv); diff --git a/getopt/getopt.1 b/getopt/getopt.1 index 410f61b..793c87a 100644 --- a/getopt/getopt.1 +++ b/getopt/getopt.1 @@ -1,69 +1,79 @@ -.\" $NetBSD: getopt.1,v 1.8 1997/10/19 02:16:57 lukem Exp $ -.Dd June 21, 1993 +.\" $FreeBSD: src/usr.bin/getopt/getopt.1,v 1.15 2002/04/19 23:43:02 charnier Exp $ +.\" +.Dd April 3, 1999 .Dt GETOPT 1 .Os .Sh NAME .Nm getopt .Nd parse command options .Sh SYNOPSIS -.Li args=\`getopt optstring $*\` -.Pp -.Li set \-\- \`getopt optstring $*\` +.Nm args=\`getopt Ar optstring $*\` +; errcode=$?; set \-\- $args .Sh DESCRIPTION +The .Nm -is used to break up options in command lines for easy parsing by +utility is used to break up options in command lines for easy parsing by shell procedures, and to check for legal options. -.Op Optstring +.Ar Optstring is a string of recognized option letters (see -.Xr getopt 3 -); +.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 \-\- +.Ql \-\- is used to delimit the end of the options. +The .Nm -will place -.Dq \-\- +utility will place +.Ql \-\- 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 \- +.Ql \- and in its own shell argument; each option argument is also in its own shell argument. -.Sh EXAMPLE +.Sh EXAMPLES The following code fragment shows how one might process the arguments for a command that can take the options -.Op a +.Fl a and -.Op b , +.Fl b , and the option -.Op o , +.Fl o , which requires an argument. .Pp .Bd -literal -offset indent args=\`getopt abo: $*\` -if test $? != 0 +# you should not use \`getopt abo: "$@"\` since that would parse +# the arguments differently from what the set command below does. +if [ $? != 0 ] then echo 'Usage: ...' exit 2 fi set \-\- $args +# You cannot use the set command with a backquoted getopt directly, +# since the exit code from getopt would be shadowed by those of set, +# which is zero by definition. for i do case "$i" in \-a|\-b) - flag=$i; shift;; + echo flag $i set; sflags="${i#-}$sflags"; + shift;; \-o) - oarg=$2; shift; shift;; + echo oarg is "'"$2"'"; oarg="$2"; shift; + shift;; \-\-) shift; break;; esac done +echo single-char flags: "'"$sflags"'" +echo oarg is "'"$oarg"'" .Ed .Pp This code will accept any of the following as equivalent: @@ -73,49 +83,52 @@ 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 "" . +.Ed .Sh SEE ALSO .Xr sh 1 , .Xr getopt 3 .Sh DIAGNOSTICS +The .Nm -prints an error message on the standard error output when it -encounters an option letter not included in -.Op optstring . +utility prints an error message on the standard error output and exits with +status > 0 when it encounters an option letter not included in +.Ar optstring . .Sh HISTORY -Written by Henry Spencer, working from a Bell Labs manual page. +Written by +.An Henry Spencer , +working from a Bell Labs manual page. Behavior believed identical to the Bell version. +Example changed in +.Fx +version 3.2 and 4.0. .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. +generally will not survive intact; this looks easy to fix but +isn't. People trying to fix +.Nm +or the example in this manpage should check the history of this file +in +.Fx . .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 "" ; +.Nm ; this again is hard to fix. .Pp The precise best way to use the -.Ic set +.Nm set command to set the arguments without disrupting the value(s) of shell options varies from one shell version to another. +.Pp +Each shellscript has to carry complex code to parse arguments halfway +correcty (like the example presented here). A better getopt-like tool +would move much of the complexity into the tool and keep the client +shell scripts simpler. diff --git a/getopt/getopt.c b/getopt/getopt.c index 7a977ea..5e8a743 100644 --- a/getopt/getopt.c +++ b/getopt/getopt.c @@ -1,21 +1,12 @@ -/* $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 */ +__RCSID("$FreeBSD: src/usr.bin/getopt/getopt.c,v 1.10 2002/09/04 23:29:01 dwmalone Exp $"); -#include #include -#include #include - -int main __P((int, char **)); +#include int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int c; int status = 0; @@ -37,5 +28,5 @@ main(argc, argv) for (; optind < argc; optind++) printf(" %s", argv[optind]); printf("\n"); - exit(status); + return status; } diff --git a/hostname/hostname.1 b/hostname/hostname.1 index c64e9f0..7700a15 100644 --- a/hostname/hostname.1 +++ b/hostname/hostname.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -32,10 +30,11 @@ .\" SUCH DAMAGE. .\" .\" @(#)hostname.1 8.2 (Berkeley) 4/28/95 +.\" $FreeBSD: src/bin/hostname/hostname.1,v 1.14 2002/04/16 20:02:56 charnier Exp $ .\" .Dd April 28, 1995 .Dt HOSTNAME 1 -.Os BSD 4.2 +.Os .Sh NAME .Nm hostname .Nd set or print name of current host system @@ -44,26 +43,21 @@ .Op Fl s .Op Ar name-of-host .Sh DESCRIPTION +The .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. +utility prints the name of the current host. +The super-user can set the hostname by supplying an argument. .Pp Options: .Bl -tag -width flag .It Fl s -Trims off any domain information from the printed +Trim off any domain information from the printed name. .El .Sh SEE ALSO -.Xr domainname 1 , -.Xr gethostname 3 , -.Xr sethostname 3 +.Xr gethostname 3 .Sh HISTORY The .Nm -utility appeared in +command appeared in .Bx 4.2 . diff --git a/hostname/hostname.c b/hostname/hostname.c index e78fe5c..a294914 100644 --- a/hostname/hostname.c +++ b/hostname/hostname.c @@ -1,5 +1,3 @@ -/* $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. @@ -33,19 +31,19 @@ * SUCH DAMAGE. */ -#include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +static char const 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 $"); +static char sccsid[] = "@(#)hostname.c 8.1 (Berkeley) 5/31/93"; #endif #endif /* not lint */ +#include +__RCSID("$FreeBSD: src/bin/hostname/hostname.c,v 1.14 2002/06/30 05:13:53 obrien Exp $"); #include @@ -55,16 +53,13 @@ __RCSID("$NetBSD: hostname.c,v 1.13 1998/07/28 05:31:24 mycroft Exp $"); #include #include -void usage __P((void)); -int main __P((int, char *[])); +void usage(void); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int ch, sflag; - char *p, hostname[MAXHOSTNAMELEN + 1]; + char *p, hostname[MAXHOSTNAMELEN]; sflag = 0; while ((ch = getopt(argc, argv, "s")) != -1) @@ -83,25 +78,25 @@ main(argc, argv) usage(); if (*argv) { - if (sethostname(*argv, strlen(*argv))) + if (sethostname(*argv, (int)strlen(*argv))) err(1, "sethostname"); } else { - if (gethostname(hostname, sizeof(hostname))) + if (gethostname(hostname, (int)sizeof(hostname))) err(1, "gethostname"); - hostname[sizeof(hostname) - 1] = '\0'; - if (sflag && (p = strchr(hostname, '.'))) - *p = '\0'; + if (sflag) { + p = strchr(hostname, '.'); + if (p != NULL) + *p = '\0'; + } (void)printf("%s\n", hostname); } exit(0); - /* NOTREACHED */ } void -usage() +usage(void) { (void)fprintf(stderr, "usage: hostname [-s] [name-of-host]\n"); exit(1); - /* NOTREACHED */ } diff --git a/id/groups.1 b/id/groups.1 index 02a90e9..dfd36a0 100644 --- a/id/groups.1 +++ b/id/groups.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -31,12 +29,12 @@ .\" 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 $ +.\" @(#)groups.1 8.1 (Berkeley) 6/6/93 +.\" $FreeBSD: src/usr.bin/id/groups.1,v 1.8 2001/08/15 09:09:41 ru Exp $ .\" .Dd June 6, 1993 .Dt GROUPS 1 -.Os BSD 3 +.Os .Sh NAME .Nm groups .Nd show group memberships @@ -58,9 +56,7 @@ 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 DIAGNOSTICS +.Ex -std .Sh SEE ALSO .Xr id 1 diff --git a/id/id.1 b/id/id.1 index b4b2bc7..c36c4f7 100644 --- a/id/id.1 +++ b/id/id.1 @@ -1,6 +1,4 @@ -.\" $NetBSD: id.1,v 1.7 1997/10/19 02:45:47 lukem Exp $ -.\" -.\" Copyright (c) 1991, 1993, 1994 +.\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by @@ -34,26 +32,31 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)id.1 8.2 (Berkeley) 5/5/94 +.\" @(#)id.1 8.1 (Berkeley) 6/6/93 +.\" $FreeBSD: src/usr.bin/id/id.1,v 1.11 2001/08/15 09:09:41 ru Exp $ .\" -.Dd May 5, 1994 +.Dd June 6, 1993 .Dt ID 1 -.Os BSD 4.4 +.Os .Sh NAME .Nm id .Nd return user identity .Sh SYNOPSIS .Nm .Op Ar user -.Nm "" +.Nm .Fl G Op Fl n .Op Ar user -.Nm "" +.Nm +.Fl P +.Op Ar user +.Nm .Fl g Op Fl nr .Op Ar user -.Nm "" +.Nm .Fl p -.Nm "" +.Op Ar user +.Nm .Fl u Op Fl nr .Op Ar user .Sh DESCRIPTION @@ -71,10 +74,12 @@ 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 +.Bl -tag -width indent .It Fl G Display the different group IDs (effective, real and supplementary) as white-space separated numbers, in no particular order. +.It Fl P +Display the id as a password file entry. .It Fl g Display the effective group ID as a number. .It Fl n @@ -93,14 +98,19 @@ If the user name returned by 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''. +is displayed, preceded by the keyword +.Dq login . +The user ID as a name is displayed, preceded by the keyword +.Dq 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''. +ID is displayed as a name, preceded by the keyword +.Dq 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''. +ID is displayed as a name, preceded by the keyword +.Dq rgid . The list of groups to which the user belongs is then displayed as names, -preceded by the keyword ``groups''. +preceded by the keyword +.Dq groups . Each display is on a separate line. .It Fl r Display the real ID for the @@ -111,10 +121,8 @@ 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 DIAGNOSTICS +.Ex -std .Sh SEE ALSO .Xr who 1 .Sh STANDARDS @@ -137,5 +145,5 @@ command is equivalent to .Pp The .Nm -command first appeared in +command appeared in .Bx 4.4 . diff --git a/id/id.c b/id/id.c index 9ef13b4..7443439 100644 --- a/id/id.c +++ b/id/id.c @@ -31,24 +31,23 @@ * SUCH DAMAGE. */ -#include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +static const char 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 $"); +static char sccsid[] = "@(#)id.c 8.2 (Berkeley) 2/16/94"; #endif #endif /* not lint */ +#include +__RCSID("$FreeBSD: src/usr.bin/id/id.c,v 1.19 2002/09/04 23:29:02 dwmalone Exp $"); #include #include -#include #include #include #include @@ -56,45 +55,47 @@ __RCSID("$NetBSD: id.c,v 1.10 1998/08/25 20:59:37 ross Exp $"); #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 *)); +void current(void); +void pline(struct passwd *); +void pretty(struct passwd *); +void group(struct passwd *, int); +void usage(void); +void user(struct passwd *); struct passwd * - who __P((char *)); + who(char *); -#ifdef __APPLE__ -extern char *__progname; -#endif +int isgroups, iswhoami; int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { struct group *gr; struct passwd *pw; - int ch, id; - int Gflag, gflag, nflag, pflag, rflag, uflag; + int Gflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; + const char *myname; - Gflag = gflag = nflag = pflag = rflag = uflag = 0; + Gflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; - if (!strcmp(__progname, "groups")) { - Gflag = 1; - nflag = 1; - } - else if (!strcmp(__progname, "whoami")) { - uflag = 1; - nflag = 1; - } + myname = strrchr(argv[0], '/'); + myname = (myname != NULL) ? myname + 1 : argv[0]; + if (strcmp(myname, "groups") == 0) { + isgroups = 1; + Gflag = nflag = 1; + } + else if (strcmp(myname, "whoami") == 0) { + iswhoami = 1; + uflag = nflag = 1; + } - while ((ch = getopt(argc, argv, "Ggnpru")) != -1) + while ((ch = getopt(argc, argv, + (isgroups || iswhoami) ? "" : "PGgnpru")) != -1) switch(ch) { case 'G': Gflag = 1; break; + case 'P': + Pflag = 1; + break; case 'g': gflag = 1; break; @@ -117,7 +118,10 @@ main(argc, argv) argc -= optind; argv += optind; - switch(Gflag + gflag + pflag + uflag) { + if (iswhoami && argc > 0) + usage(); + + switch(Gflag + Pflag + gflag + pflag + uflag) { case 1: break; case 0: @@ -153,6 +157,11 @@ main(argc, argv) exit(0); } + if (Pflag) { + pline(pw); + exit(0); + } + if (pflag) { pretty(pw); exit(0); @@ -166,8 +175,7 @@ main(argc, argv) } void -pretty(pw) - struct passwd *pw; +pretty(struct passwd *pw) { struct group *gr; u_int eid, rid; @@ -188,15 +196,15 @@ pretty(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) + if ((pw = getpwuid(eid))) (void)printf("euid\t%s\n", pw->pw_name); else (void)printf("euid\t%u\n", eid); } if ((rid = getgid()) != (eid = getegid())) { - if ((gr = getgrgid(rid)) != NULL) + if ((gr = getgrgid(rid))) (void)printf("rgid\t%s\n", gr->gr_name); else (void)printf("rgid\t%u\n", rid); @@ -207,40 +215,40 @@ pretty(pw) } void -current() +current(void) { struct group *gr; struct passwd *pw; int cnt, id, eid, lastid, ngroups; gid_t groups[NGROUPS]; - char *fmt; + const char *fmt; id = getuid(); (void)printf("uid=%u", id); - if ((pw = getpwuid(id)) != NULL) + if ((pw = getpwuid(id))) (void)printf("(%s)", pw->pw_name); if ((eid = geteuid()) != id) { (void)printf(" euid=%u", eid); - if ((pw = getpwuid(eid)) != NULL) + if ((pw = getpwuid(eid))) (void)printf("(%s)", pw->pw_name); } id = getgid(); (void)printf(" gid=%u", id); - if ((gr = getgrgid(id)) != NULL) + if ((gr = getgrgid(id))) (void)printf("(%s)", gr->gr_name); if ((eid = getegid()) != id) { (void)printf(" egid=%u", eid); - if ((gr = getgrgid(eid)) != NULL) + if ((gr = getgrgid(eid))) (void)printf("(%s)", gr->gr_name); } - if ((ngroups = getgroups(NGROUPS, groups)) != NULL) { + if ((ngroups = getgroups(NGROUPS, groups))) { 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) + if ((gr = getgrgid(id))) (void)printf("(%s)", gr->gr_name); } } @@ -248,42 +256,39 @@ current() } void -user(pw) - struct passwd *pw; +user(struct passwd *pw) { struct group *gr; - char *fmt; - int cnt, id, lastid, ngroups, groups[NGROUPS + 1]; + const char *fmt; + int cnt, gid, lastgid, 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("uid=%u(%s)", pw->pw_uid, pw->pw_name); + gid = pw->pw_gid; + (void)printf(" gid=%u", gid); + if ((gr = getgrgid(gid))) (void)printf("(%s)", gr->gr_name); ngroups = NGROUPS + 1; - (void) getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); + (void) getgrouplist(pw->pw_name, gid, groups, &ngroups); fmt = " groups=%u"; - for (lastid = -1, cnt = 0; cnt < ngroups; ++cnt) { - if (lastid == (id = groups[cnt])) + for (lastgid = -1, cnt = 0; cnt < ngroups; ++cnt) { + if (lastgid == (gid = groups[cnt])) continue; - (void)printf(fmt, id); - fmt = " %u"; - if ((gr = getgrgid(id)) != NULL) + (void)printf(fmt, gid); + fmt = ", %u"; + if ((gr = getgrgid(gid))) (void)printf("(%s)", gr->gr_name); - lastid = id; + lastgid = gid; } (void)printf("\n"); } void -group(pw, nflag) - struct passwd *pw; - int nflag; +group(struct passwd *pw, int nflag) { struct group *gr; int cnt, id, lastid, ngroups; gid_t groups[NGROUPS + 1]; - char *fmt; + const char *fmt; if (pw) { ngroups = NGROUPS + 1; @@ -297,7 +302,7 @@ group(pw, nflag) if (lastid == (id = groups[cnt])) continue; if (nflag) { - if ((gr = getgrgid(id)) != NULL) + if ((gr = getgrgid(id))) (void)printf(fmt, gr->gr_name); else (void)printf(*fmt == ' ' ? " %u" : "%u", @@ -313,8 +318,7 @@ group(pw, nflag) } struct passwd * -who(u) - char *u; +who(char *u) { struct passwd *pw; long id; @@ -324,22 +328,47 @@ who(u) * 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) + if ((pw = getpwnam(u))) return(pw); id = strtol(u, &ep, 10); if (*u && !*ep && (pw = getpwuid(id))) return(pw); - errx(1, "%s: No such user", u); + errx(1, "%s: no such user", u); /* NOTREACHED */ - return (NULL); } void -usage() +pline(struct passwd *pw) +{ + u_int rid; + + if (!pw) { + if ((pw = getpwuid(rid = getuid())) == NULL) + err(1, "getpwuid"); + } + + (void)printf("%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n", pw->pw_name, + pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class, + (long)pw->pw_change, (long)pw->pw_expire, pw->pw_gecos, + pw->pw_dir, pw->pw_shell); +} + + +void +usage(void) { - (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"); + + if (isgroups) + (void)fprintf(stderr, "usage: groups [user]\n"); + else if (iswhoami) + (void)fprintf(stderr, "usage: whoami\n"); + else + (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", + "usage: id [user]", + " id -G [-n] [user]", + " id -P [user]", + " id -g [-nr] [user]", + " id -p [user]", + " id -u [-nr] [user]"); exit(1); } diff --git a/id/whoami.1 b/id/whoami.1 index 38666fb..bf201d8 100644 --- a/id/whoami.1 +++ b/id/whoami.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -31,12 +29,12 @@ .\" 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 $ +.\" @(#)whoami.1 8.1 (Berkeley) 6/6/93 +.\" $FreeBSD: src/usr.bin/id/whoami.1,v 1.8 2001/08/15 09:09:41 ru Exp $ .\" .Dd June 6, 1993 .Dt WHOAMI 1 -.Os BSD 3 +.Os .Sh NAME .Nm whoami .Nd display effective user id @@ -56,9 +54,7 @@ is suggested for normal interactive use. 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 DIAGNOSTICS +.Ex -std .Sh SEE ALSO .Xr id 1 diff --git a/jot/jot.1 b/jot/jot.1 index 0d13232..3ae05e4 100644 --- a/jot/jot.1 +++ b/jot/jot.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -32,37 +30,32 @@ .\" SUCH DAMAGE. .\" .\" @(#)jot.1 8.1 (Berkeley) 6/6/93 +.\" $FreeBSD: src/usr.bin/jot/jot.1,v 1.14 2002/07/03 12:24:11 ru Exp $ .\" -.Dd November 1, 1997 +.Dd June 6, 1993 .Dt JOT 1 .Os .Sh NAME .Nm jot .Nd print sequential or random data .Sh SYNOPSIS -.Nm jot -.Op Fl rcn +.Nm +.Op Fl cnr .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 +.Op Ar reps Op Ar begin Op Ar end Op Ar s .Sh DESCRIPTION The -.Nm jot +.Nm utility is used to print out increasing, decreasing, random, -or redundant data (usually numbers) one per line. +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. +Generate random data instead of the default sequential data. .It Fl b Ar word Just print .Ar word @@ -71,7 +64,9 @@ repetitively. Print .Ar word with the generated data appended to it. -Octal, hexadecimal, exponential, ASCII, zero padded, +Octal, hexadecimal, exponential, +.Tn ASCII , +zero padded, and right-adjusted representations are possible by using the appropriate .Xr printf 3 @@ -79,7 +74,8 @@ 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. +This is an abbreviation for +.Fl w Ar %c . .It Fl s Ar string Print data separated by .Ar string . @@ -110,7 +106,7 @@ 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 - . +.Fl "" . Any three of these arguments determines the fourth. If four are specified and the given and computed values of .Ar reps @@ -126,72 +122,94 @@ 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. +the seed, +.Ar s , +is picked randomly. +The .Ar reps -is expected to be an unsigned integer, +argument is expected to be an unsigned integer, and if given as zero is taken to be infinite. +The .Ar begin and .Ar end -may be given as real numbers or as characters -representing the corresponding value in ASCII. +arguments may be given as real numbers or as characters +representing the corresponding value in +.Tn ASCII . The last argument must be a real number. .Pp Random numbers are obtained through .Xr random 3 . The name -.Nm jot +.Nm 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. +The command +.Dl jot 21 -1 1.00 .Pp -The command: -.Dl "jot \-c 128 0" -prints the ASCII character set. +prints 21 evenly spaced numbers increasing from -1 to 1. +The +.Tn ASCII +character set is generated with +.Dl jot -c 128 0 .Pp -The command: -.Dl "jot \-w xa%c 26 a" -prints the strings -.Dq xaa -through -.Dq xaz . +and the strings xaa through xaz with +.Dl jot -w xa%c 26 a .Pp -The command: -.Dl "jot \-r \-c 160 a z | rs \-g 0 8" -prints 20 random 8-letter strings. +while 20 random 8-letter strings are produced with +.Dl "jot -r -c 160 a z | rs -g 0 8" .Pp -The command: -.Dl "jot \-b y 0" -is equivalent to -.Xr yes 1 . +Infinitely many +.Em yes Ns 's +may be obtained through +.Dl jot -b yes 0 .Pp -The command: -.Dl "jot \-w %ds/old/new/ 30 2 \- 5" -prints thirty +and thirty .Xr ed 1 -substitution commands applying to lines 2, 7, 12, etc. +substitution commands applying to lines 2, 7, 12, etc. is +the result of +.Dl jot -w %ds/old/new/ 30 2 - 5 .Pp -The command: -.Dl "jot 0 9 \- \-.5" -prints the stuttering sequence 9, 9, 8, 8, 7, etc. +The stuttering sequence 9, 9, 8, 8, 7, etc. can be +produced by suitable choice of step size, +as in +.Dl jot - 9 0 -.5 .Pp -The command: -.Dl "jot \-b x 512 > block" -creates a file containing exactly 1024 bytes. +and a file containing exactly 1024 bytes is created with +.Dl jot -b x 512 > block .Pp -The command: -.Dl "expand \-\`jot \-s, \- 10 132 4\`" -sets tabs four spaces apart starting -from column 10 and ending in column 132. +Finally, to set tabs four spaces apart starting +from column 10 and ending in column 132, use +.Dl expand -`jot -s, - 10 132 4` .Pp -The command: -.Dl "grep \`jot \-s """" \-b . 80\`" -prints all lines 80 characters or longer. +and to print all lines 80 characters or longer, +.Dl grep `jot -s \&"\&" -b \&. 80` +.Sh DIAGNOSTICS +.Ex -std +The following diagnostic messages deserve special explanation: +.Bl -diag +.It "illegal or unsupported format '%s'" +The requested conversion format specifier for +.Xr printf 3 +was not of the form +.Dl %[#][ ][{+,-}][0-9]*[.[0-9]*]? +where +.Dq ?\& +must be one of +.Dl [l]{d,i,o,u,x} +or +.Dl {c,e,f,g,D,E,G,O,U,X} +.It "range error in conversion" +A value to be printed fell outside the range of the data type +associated with the requested output format. +.It "too many conversions" +More than one conversion format specifier has been supplied, +but only one is allowed. +.El +.Sh AUTHOR +John A. Kunze .Sh SEE ALSO .Xr ed 1 , .Xr expand 1 , diff --git a/jot/jot.c b/jot/jot.c index 92b9f9e..b257793 100644 --- a/jot/jot.c +++ b/jot/jot.c @@ -1,5 +1,3 @@ -/* $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. @@ -33,18 +31,19 @@ * SUCH DAMAGE. */ -#include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +static const char 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 */ +#endif +#include +__RCSID("$FreeBSD: src/usr.bin/jot/jot.c,v 1.24 2002/07/05 15:58:27 mike Exp $"); /* * jot - print sequential or random data @@ -56,16 +55,18 @@ __RCSID("$NetBSD: jot.c,v 1.4 1997/10/19 03:34:49 lukem Exp $"); #include #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) +#define is_default(s) (strcmp((s), "-") == 0) double begin; double ender; @@ -75,57 +76,33 @@ int randomize; int infinity; int boring; int prec; -int dox; +int longdata; +int intdata; int chardata; +int nosign; int nofinalnl; -char sepstring[BUFSIZ] = "\n"; +const char *sepstring = "\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)); +void getformat(void); +int getprec(char *); +int putdata(double, long); +static void usage(void); int -main(argc, argv) - int argc; - char *argv[]; +main(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; + int n = 0; + int ch; - while (--ac && **++av == '-' && !isdefault(*av)) - switch ((*av)[1]) { + while ((ch = getopt(argc, argv, "rb:w:cs:np:")) != -1) + switch (ch) { case 'r': randomize = 1; break; @@ -137,72 +114,63 @@ getargs(ac, av) break; case 'b': boring = 1; + /* FALLTHROUGH */ case 'w': - if ((*av)[2]) - strcpy(format, *av + 2); - else if (!--ac) - error("Need context word after -w or -b", ""); - else - strcpy(format, *++av); + if (strlcpy(format, optarg, sizeof(format)) >= + sizeof(format)) + errx(1, "-%c word too long", ch); break; case 's': - if ((*av)[2]) - strcpy(sepstring, *av + 2); - else if (!--ac) - error("Need string after -s", ""); - else - strcpy(sepstring, *++av); + sepstring = optarg; break; case 'p': - if ((*av)[2]) - prec = atoi(*av + 2); - else if (!--ac) - error("Need number after -p", ""); - else - prec = atoi(*++av); + prec = atoi(optarg); if (prec <= 0) - error("Bad precision value", ""); + errx(1, "bad precision value"); break; default: - error("Unknown option %s", *av); + usage(); } + argc -= optind; + argv += optind; - switch (ac) { /* examine args right to left, falling thru cases */ + switch (argc) { /* 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]); + if (!is_default(argv[3])) { + if (!sscanf(argv[3], "%lf", &s)) + errx(1, "bad s value: %s", argv[3]); mask |= 01; } case 3: - if (!isdefault(av[2])) { - if (!sscanf(av[2], "%lf", &ender)) - ender = av[2][strlen(av[2])-1]; + if (!is_default(argv[2])) { + if (!sscanf(argv[2], "%lf", &ender)) + ender = argv[2][strlen(argv[2])-1]; mask |= 02; if (!prec) - n = getprec(av[2]); + n = getprec(argv[2]); } case 2: - if (!isdefault(av[1])) { - if (!sscanf(av[1], "%lf", &begin)) - begin = av[1][strlen(av[1])-1]; + if (!is_default(argv[1])) { + if (!sscanf(argv[1], "%lf", &begin)) + begin = argv[1][strlen(argv[1])-1]; mask |= 04; if (!prec) - prec = getprec(av[1]); + prec = getprec(argv[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]); + if (!is_default(argv[0])) { + if (!sscanf(argv[0], "%ld", &reps)) + errx(1, "bad reps value: %s", argv[0]); mask |= 010; } break; case 0: - error("jot - print sequential or random data", ""); + usage(); default: - error("Too many arguments. What do you mean by %s?", av[4]); + errx(1, "too many arguments. What do you mean by %s?", + argv[4]); } getformat(); while (mask) /* 4 bit mask has 1's where last 4 args were given */ @@ -244,7 +212,7 @@ getargs(ac, av) } reps = (ender - begin + s) / s; if (reps <= 0) - error("Impossible stepsize", ""); + errx(1, "impossible stepsize"); mask = 0; break; case 010: @@ -256,19 +224,19 @@ getargs(ac, av) mask = 015; break; case 012: - s = (randomize ? time(0) : STEP_DEF); + s = (randomize ? time(NULL) : STEP_DEF); mask = 013; break; case 013: if (randomize) begin = BEGIN_DEF; else if (reps == 0) - error("Must specify begin if reps == 0", ""); + errx(1, "must specify begin if reps == 0"); begin = ender - reps * s + s; mask = 0; break; case 014: - s = (randomize ? time(0) : STEP_DEF); + s = (randomize ? -1.0 : STEP_DEF); mask = 015; break; case 015: @@ -280,10 +248,9 @@ getargs(ac, av) break; case 016: if (randomize) - s = time(0); + s = -1.0; else if (reps == 0) - error("Infinite sequences cannot be bounded", - ""); + errx(1, "infinite sequences cannot be bounded"); else if (reps == 1) s = 0.0; else @@ -294,64 +261,84 @@ getargs(ac, av) if (!randomize && s != 0.0) { long t = (ender - begin + s) / s; if (t <= 0) - error("Impossible stepsize", ""); + errx(1, "impossible stepsize"); if (t < reps) /* take lesser */ reps = t; } mask = 0; break; default: - error("Bad mask", ""); + errx(1, "bad mask"); } if (reps == 0) infinity = 1; + if (randomize) { + *x = (ender - begin) * (ender > begin ? 1 : -1); + for (*i = 1; *i <= reps || infinity; (*i)++) { + *y = arc4random() / (double)UINT32_MAX; + if (putdata(*y * *x + begin, reps - *i)) + errx(1, "range error in conversion"); + } + } else + for (*i = 1, *x = begin; *i <= reps || infinity; (*i)++, *x += s) + if (putdata(*x, reps - *i)) + errx(1, "range error in conversion"); + if (!nofinalnl) + putchar('\n'); + exit(0); } -void -putdata(x, notlast) - double x; - long notlast; +int +putdata(double x, long int notlast) { - long d = x; - long *dp = &d; - if (boring) /* repeated word */ + if (boring) printf("%s", format); - else if (dox) /* scalar */ - printf(format, *dp); - else /* real */ + else if (longdata && nosign) { + if (x <= (double)ULONG_MAX && x >= (double)0) + printf(format, (unsigned long)x); + else + return (1); + } else if (longdata) { + if (x <= (double)LONG_MAX && x >= (double)LONG_MIN) + printf(format, (long)x); + else + return (1); + } else if (chardata || (intdata && !nosign)) { + if (x <= (double)INT_MAX && x >= (double)INT_MIN) + printf(format, (int)x); + else + return (1); + } else if (intdata) { + if (x <= (double)UINT_MAX && x >= (double)0) + printf(format, (unsigned int)x); + else + return (1); + + } else printf(format, x); if (notlast != 0) fputs(sepstring, stdout); + + return (0); } -void -error(msg, s) - char *msg, *s; +static void +usage(void) { - 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"); + fprintf(stderr, "%s\n%s\n", + "usage: jot [-cnr] [-b word] [-w word] [-s string] [-p precision]", + " [reps [begin [end [s]]]]"); exit(1); } int -getprec(s) - char *s; +getprec(char *str) { char *p; char *q; - for (p = s; *p; p++) + for (p = str; *p; p++) if (*p == '.') break; if (!*p) @@ -363,37 +350,101 @@ getprec(s) } void -getformat() +getformat(void) { - char *p; + char *p, *p2; + int dot, hash, space, sign, numbers = 0; + size_t sz; 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)) + sz = sizeof(format) - strlen(format) - 1; + if (!*p && !chardata) { + if (snprintf(p, sz, "%%.%df", prec) >= (int)sz) + errx(1, "-w word too long"); + } else if (!*p && chardata) { + if (strlcpy(p, "%c", sz) >= sz) + errx(1, "-w word too long"); + intdata = 1; + } else if (!*(p+1)) { + if (sz <= 0) + errx(1, "-w word too long"); strcat(format, "%"); /* cannot end in single '%' */ - else { - while (!isalpha(*p)) - p++; + } else { + /* + * Allow conversion format specifiers of the form + * %[#][ ][{+,-}][0-9]*[.[0-9]*]? where ? must be one of + * [l]{d,i,o,u,x} or {f,e,g,E,G,d,o,x,D,O,U,X,c,u} + */ + p2 = p++; + dot = hash = space = sign = numbers = 0; + while (!isalpha(*p)) { + if (isdigit(*p)) { + numbers++; + p++; + } else if ((*p == '#' && !(numbers|dot|sign|space| + hash++)) || + (*p == ' ' && !(numbers|dot|space++)) || + ((*p == '+' || *p == '-') && !(numbers|dot|sign++)) + || (*p == '.' && !(dot++))) + p++; + else + goto fmt_broken; + } + if (*p == 'l') { + longdata = 1; + if (*++p == 'l') { + if (p[1] != '\0') + p++; + goto fmt_broken; + } + } switch (*p) { - case 'f': case 'e': case 'g': case '%': + case 'o': case 'u': case 'x': case 'X': + intdata = nosign = 1; break; - case 's': - error("Cannot convert numeric data to strings", ""); + case 'd': case 'i': + intdata = 1; break; - /* case 'd': case 'o': case 'x': case 'D': case 'O': case 'X': - case 'c': case 'u': */ + case 'D': + if (!longdata) { + intdata = 1; + break; + } + case 'O': case 'U': + if (!longdata) { + intdata = nosign = 1; + break; + } + case 'c': + if (!(intdata | longdata)) { + chardata = 1; + break; + } + case 'h': case 'n': case 'p': case 'q': case 's': case 'L': + case '$': case '*': + goto fmt_broken; + case 'f': case 'e': case 'g': case 'E': case 'G': + if (!longdata) + break; + /* FALLTHROUGH */ default: - dox = 1; - break; +fmt_broken: + *++p = '\0'; + errx(1, "illegal or unsupported format '%s'", p2); + /* NOTREACHED */ } + while (*++p) + if (*p == '%' && *(p+1) && *(p+1) != '%') + errx(1, "too many conversions"); + else if (*p == '%' && *(p+1) == '%') + p++; + else if (*p == '%' && !*(p+1)) { + strcat(format, "%"); + break; + } } } diff --git a/killall/killall.c b/killall/killall.c index f31d084..25a2ded 100644 --- a/killall/killall.c +++ b/killall/killall.c @@ -115,7 +115,11 @@ main(int ac, char **av) int mflag = 0; uid_t uid = 0; dev_t tdev = 0; - char thiscmd[MAXCOMLEN + 1]; +#ifdef OLD_STYLE + char thiscmd[MAXCOMLEN+1]; +#else + char *thiscmd; +#endif pid_t thispid; uid_t thisuid; dev_t thistdev; @@ -286,9 +290,64 @@ main(int ac, char **av) printf("nprocs %d\n", nprocs); for (i = 0; i < nprocs; i++) { - thispid = procs[i].kp_proc.p_pid; - strncpy(thiscmd, procs[i].kp_proc.p_comm, MAXCOMLEN); +#ifndef OLD_STYLE + int mib[3], argmax; + size_t syssize; + char *procargs, *cp; + + mib[0] = CTL_KERN; + mib[1] = KERN_ARGMAX; + + syssize = sizeof(argmax); + if (sysctl(mib, 2, &argmax, &syssize, NULL, 0) == -1) + continue; + + procargs = malloc(argmax); + if (procargs == NULL) + continue; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROCARGS; + mib[2] = procs[i].kp_proc.p_pid; + + syssize = (size_t)argmax; + if (sysctl(mib, 3, procargs, &syssize, NULL, 0) == -1) { + free(procargs); + continue; + } + + for (cp = procargs; cp < &procargs[syssize]; cp++) { + if (*cp == '\0') { + break; + } + } + if (cp == &procargs[syssize]) { + free(procargs); + continue; + } + + for (; cp < &procargs[syssize]; cp++) { + if (*cp != '\0') { + break; + } + } + + if (cp == &procargs[syssize]) { + free(procargs); + continue; + } + + /* Strip off any path that was specified */ + for (thiscmd = cp; (cp < &procargs[syssize]) && (*cp != '\0'); cp++) { + if( *cp == '/' ) { + thiscmd = cp+1; + } + } +#else thiscmd[MAXCOMLEN] = '\0'; +#endif + thispid = procs[i].kp_proc.p_pid; + thistdev = procs[i].kp_eproc.e_tdev; thisuid = procs[i].kp_eproc.e_pcred.p_ruid; /* real uid */ @@ -321,8 +380,12 @@ main(int ac, char **av) matched = 0; } } - if (matched == 0) + if (matched == 0) { +#ifndef OLD_STYLE + free(procargs); +#endif continue; + } if (ac > 0) matched = 0; for (j = 0; j < ac; j++) { @@ -347,8 +410,12 @@ main(int ac, char **av) if (matched) break; } - if (matched == 0) + if (matched == 0) { +#ifndef OLD_STYLE + free(procargs); +#endif continue; + } if (dflag) printf("sig:%d, cmd:%s, pid:%d, dev:0x%x uid:%d\n", sig, thiscmd, thispid, thistdev, thisuid); diff --git a/locate/locate/Makefile b/locate/locate/Makefile index c50d9fa..8682185 100644 --- a/locate/locate/Makefile +++ b/locate/locate/Makefile @@ -17,7 +17,7 @@ HFILES = locate.h pathnames.h CFILES = locate.c OTHERSRCS = Makefile Makefile.preamble Makefile.postamble locate.1\ - updatedb.csh + updatedb.csh locate.updatedb.8 MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles diff --git a/locate/locate/PB.project b/locate/locate/PB.project index e2d36fe..9e2813b 100644 --- a/locate/locate/PB.project +++ b/locate/locate/PB.project @@ -4,7 +4,7 @@ FRAMEWORKS = (); H_FILES = (locate.h, pathnames.h); OTHER_LINKED = (locate.c); - OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, locate.1, updatedb.csh); + OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, locate.1, locate.updatedb.8, updatedb.csh); SUBPROJECTS = (); }; LANGUAGE = English; diff --git a/locate/locate/locate.updatedb.8 b/locate/locate/locate.updatedb.8 new file mode 100755 index 0000000..7408d0f --- /dev/null +++ b/locate/locate/locate.updatedb.8 @@ -0,0 +1,90 @@ +.\" $OpenBSD: locate.updatedb.8,v 1.3 1997/01/04 01:36:01 millert Exp $ +.\" +.\" Copyright (c) 1996 +.\" Mike Pritchard . 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 Mike Pritchard. +.\" 4. Neither the name of the author 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 AUTHOR 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. +.\" +.Dd February 11, 1996 +.Dt LOCATE.UPDATEDB 8 +.Os BSD 4.4 +.Sh NAME +.Nm locate.updatedb +.Nd update locate database +.Sh SYNOPSIS +.Nm /usr/libexec/locate.updatedb +.Op Fl --tmpdir=dir +.Op Fl --fcodes=dbfile +.Op Fl --searchpaths='dir1 dir2...' +.Op Fl --prunepaths='dir1 dir2...' +.Op Fl --filesystems='type1 type2...' +.Sh DESCRIPTION +.Nm Locate.updatedb +updates the database used by +.Xr locate 1 . +It is typically run once a week by the +.Pa /etc/weekly +script. +.Pp +The contents of the newly built database can be controlled by the +.Pa /etc/locate.rc +file as well as the command line arguments. +.Sh OPTIONS +.Bl -tag -width --filesystems +The available options are as follows: +.It Fl --tmpdir +Sets the directory temporary files are stored in. +.It Fl --fcodes +Use the named file as the find codes database. If the file +name ``-'' is given, the database will be sent to standard output. +.It Fl --searchpaths +Sets the list of directories to be put in the database. +.It Fl --prunepaths +Sets the list of parent directories that should not be go in +the database. +.It Fl --filesystems +A list of filesystem types to be traversed by +.Xr find 1 . +.El +.Sh FILES +.Bl -tag -width /var/db/locate.database -compact +.It Pa /var/db/locate.database +the default database +.It Pa /etc/locate.rc +the configuration file +.El +.Sh SEE ALSO +.Xr locate 1 +.Rs +.%A Woods, James A. +.%D 1983 +.%T "Finding Files Fast" +.%J ";login" +.%V 8:1 +.%P pp. 8-10 +.Re diff --git a/locate/locate/updatedb.csh b/locate/locate/updatedb.csh index 88f977e..8347169 100644 --- a/locate/locate/updatedb.csh +++ b/locate/locate/updatedb.csh @@ -42,7 +42,7 @@ 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 (! $?TMPDIR) setenv TMPDIR /tmp if (! $?DBDIR) setenv DBDIR /var/db set FCODES = $DBDIR/locate.database # the database diff --git a/printf/printf.1 b/printf/printf.1 index bc63d9b..8db9738 100644 --- a/printf/printf.1 +++ b/printf/printf.1 @@ -271,10 +271,15 @@ exits 0 on success, 1 on failure. .Sh STANDARDS The .Nm -utility conforms to +utility mostly 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. +.Pp +Parsing of - arguments is also somewhat different from +.Xr printf 3 , +where unknown arguments are simply printed instead of being +flagged as errors. diff --git a/renice/renice.c b/renice/renice.c index 3fd63ce..abc9b20 100644 --- a/renice/renice.c +++ b/renice/renice.c @@ -131,6 +131,6 @@ donice(which, who, prio) warn("%d: setpriority", who); return (1); } - printf("%d: old priority %d, new priority %d\n", who, oldprio, prio); + fprintf(stderr, "%d: old priority %d, new priority %d\n", who, oldprio, prio); return (0); } diff --git a/su/su.c b/su/su.c index 2d7018c..aad3cad 100644 --- a/su/su.c +++ b/su/su.c @@ -362,8 +362,8 @@ main(int argc, char *argv[]) if (asme) *np.a-- = "-m"; } - /* csh strips the first character... */ - *np.a = asthem ? "-su" : iscsh == YES ? "_su" : "su"; + /* csh *no longer* strips the first character... */ + *np.a = asthem ? "-su" : "su"; if (ruid != 0) syslog(LOG_NOTICE, "%s to %s%s", username, user, diff --git a/w/Makefile b/w/Makefile index 3c5c7cf..66fdc32 100644 --- a/w/Makefile +++ b/w/Makefile @@ -23,12 +23,12 @@ MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles CODE_GEN_STYLE = DYNAMIC MAKEFILE = tool.make NEXTSTEP_INSTALLDIR = /usr/bin -LIBS = +LIBS = -lresolv DEBUG_LIBS = $(LIBS) PROF_LIBS = $(LIBS) -NEXTSTEP_PB_CFLAGS = -traditional-cpp -Wno-error +NEXTSTEP_PB_CFLAGS = -no-cpp-precomp -Wno-error -DSUCKAGE=1000000000000 NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(NAME)/Build diff --git a/w/Makefile.postamble b/w/Makefile.postamble index d6c7e60..900c488 100644 --- a/w/Makefile.postamble +++ b/w/Makefile.postamble @@ -1,7 +1,4 @@ include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common -INSTALL_AS_GROUP = kmem -INSTALL_PERMISSIONS = 2555 - after_install:: $(LINKPRODUCT) $(DSTROOT)$(INSTALLDIR)/uptime diff --git a/w/extern.h b/w/extern.h index 7562e03..ba7a1ad 100644 --- a/w/extern.h +++ b/w/extern.h @@ -1,5 +1,3 @@ -/* $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. @@ -33,11 +31,15 @@ * SUCH DAMAGE. * * @(#)extern.h 8.1 (Berkeley) 6/6/93 + * $FreeBSD: src/usr.bin/w/extern.h,v 1.5 2002/03/22 01:42:43 imp Exp $ */ -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 *)); + +extern int use_ampm; + +struct extern_proc; +void pr_attime(time_t *, time_t *); +int pr_idle(time_t); +int proc_compare(struct extern_proc *, struct extern_proc *); + +#define KI_PROC(ki) (&(ki)->kp->kp_proc) diff --git a/w/fmt.c b/w/fmt.c index c3606ab..5df1c8c 100644 --- a/w/fmt.c +++ b/w/fmt.c @@ -1,56 +1,133 @@ +/*- + * Copyright (c) 1992, 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 + +#if 0 +#ifndef lint +static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94"; +#endif +#endif + +#include +#include +#include + +#include #include #include #include #include #include -#include -#include -/*#include "ps.h"*/ -#include "extern.h" -void -fmt_puts(s, leftp) - char *s; - int *leftp; +//#include "ps.h" + +static char *cmdpart(char *); +static char *shquote(char **); + +/* + * XXX + * This is a stub until marc does the real one. + */ +static char * +shquote(char **argv) { - 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; + static long arg_max = -1; + size_t len; + char **p, *dst, *src; + static char *buf = NULL; + + if (buf == NULL) { + if ((arg_max = sysconf(_SC_ARG_MAX)) == -1) + errx(1, "sysconf _SC_ARG_MAX failed"); + if ((buf = malloc((u_int)(4 * arg_max) + 1)) == NULL) + errx(1, "malloc failed"); } - 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; + + if (*argv == 0) { + buf[0] = 0; + return (buf); } - printf("%s", v); + dst = buf; + for (p = argv; (src = *p++) != 0; ) { + if (*src == 0) + continue; + len = (size_t)(4 * arg_max - (dst - buf)) / 4; + strvisx(dst, src, strlen(src) < len ? strlen(src) : len, + VIS_NL | VIS_CSTYLE); + while (*dst) + dst++; + if ((4 * arg_max - (dst - buf)) / 4 > 0) + *dst++ = ' '; + } + /* Chop off trailing space */ + if (dst != buf && dst[-1] == ' ') + dst--; + *dst = '\0'; + return (buf); } -void -fmt_putc(c, leftp) - int c; - int *leftp; +static char * +cmdpart(char *arg0) { + char *cp; - if (*leftp == 0) - return; - if (*leftp != -1) - *leftp -= 1; - putchar(c); + return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0); +} + +const char * +fmt_argv(char **argv, char *cmd, size_t maxlen) +{ + size_t len; + char *ap, *cp; + + if (argv == NULL || argv[0] == NULL) { + if (cmd == NULL) + return (""); + ap = NULL; + len = maxlen + 3; + } else { + ap = shquote(argv); + len = strlen(ap) + maxlen + 4; + } + cp = malloc(len); + if (cp == NULL) + return (NULL); + if (ap == NULL) + sprintf(cp, " (%.*s)", (int)maxlen, cmd); + else if (strncmp(cmdpart(argv[0]), cmd, maxlen) != 0) + sprintf(cp, "%s (%.*s)", ap, (int)maxlen, cmd); + else + (void) strcpy(cp, ap); + return (cp); } diff --git a/w/pr_time.c b/w/pr_time.c index e05edb5..5027d9f 100644 --- a/w/pr_time.c +++ b/w/pr_time.c @@ -1,5 +1,3 @@ -/* $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. @@ -34,83 +32,88 @@ */ #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 $"); +static const char sccsid[] = "@(#)pr_time.c 8.2 (Berkeley) 4/4/94"; #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. + * Print the time since the user logged in. */ void pr_attime(started, now) time_t *started, *now; { static char buf[256]; - int tnow_yday; - struct tm *tp; + struct tm tp, tm; time_t diff; - char *fmt; + char fmt[20]; - tnow_yday = localtime(now)->tm_yday; - tp = localtime(started); + tp = *localtime(started); + tm = *localtime(now); diff = *now - *started; /* If more than a week, use day-month-year. */ - if (diff > SECSPERDAY * DAYSPERWEEK) - fmt = "%d%b%y"; + if (diff > 86400 * 7) + (void)strcpy(fmt, "%d%b%y"); /* If not today, use day-hour-am/pm. */ - else if (tp->tm_yday != tnow_yday) - fmt = __CONCAT("%a%", "I%p"); + else if (tm.tm_mday != tp.tm_mday || + tm.tm_mon != tp.tm_mon || + tm.tm_year != tp.tm_year) { + /* The line below does not take DST into consideration */ + /* else if (*now / 86400 != *started / 86400) { */ + (void)strcpy(fmt, use_ampm ? "%a%I%p" : "%a%H"); + } /* Default is hh:mm{am,pm}. */ - else - fmt = __CONCAT("%l:%", "M%p"); + else { + (void)strcpy(fmt, use_ampm ? "%l:%M%p" : "%k:%M"); + } - (void)strftime(buf, sizeof(buf), fmt, tp); - buf[sizeof(buf) - 1] = '\0'; - (void)fputs(buf, stdout); + (void)strftime(buf, sizeof(buf), fmt, &tp); + (void)printf("%-7.7s", buf); } /* * pr_idle -- * Display the idle time. + * Returns number of excess characters that were used for long idle time. */ -void +int 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 >= 36 * 3600) { + int days = idle / 86400; + (void)printf(" %dday%s ", days, days > 1 ? "s" : " " ); + if (days >= 100) + return (2); + if (days >= 10) + return (1); + } /* If idle more than an hour, print as HH:MM. */ - else if (idle >= SECSPERHOUR) + else if (idle >= 3600) (void)printf(" %2d:%02d ", - (int)(idle / SECSPERHOUR), - (int)((idle % SECSPERHOUR) / SECSPERMIN)); + (int)(idle / 3600), (int)((idle % 3600) / 60)); + + else if (idle / 60 == 0) + (void)printf(" - "); /* Else print the minutes idle. */ else - (void)printf(" %2d ", (int)(idle / SECSPERMIN)); + (void)printf(" %2d ", (int)(idle / 60)); + + return (0); /* not idle longer than 9 days */ } diff --git a/w/proc_compare.c b/w/proc_compare.c index 7a15cac..f07638a 100644 --- a/w/proc_compare.c +++ b/w/proc_compare.c @@ -1,5 +1,3 @@ -/* $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. @@ -34,17 +32,14 @@ */ #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 $"); +static const char sccsid[] = "@(#)proc_compare.c 8.2 (Berkeley) 9/23/93"; #endif -#endif /* not lint */ #include #include -#include +#include #include "extern.h" @@ -58,7 +53,7 @@ __RCSID("$NetBSD: proc_compare.c,v 1.7 1997/10/20 02:49:14 mrg Exp $"); * 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). + * we pick out just "short-term" sleepers (PS_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 @@ -67,7 +62,10 @@ __RCSID("$NetBSD: proc_compare.c,v 1.7 1997/10/20 02:49:14 mrg Exp $"); * TODO - consider whether pctcpu should be used. */ -#define ISRUN(p) (((p)->p_stat == SRUN) || ((p)->p_stat == SIDL)) +#include + + +#define ISRUN(p) (((p)->p_stat == SRUN) || ((p)->p_stat == SIDL)) #define TESTAB(a, b) ((a)<<1 | (b)) #define ONLYA 2 #define ONLYB 1 @@ -75,7 +73,7 @@ __RCSID("$NetBSD: proc_compare.c,v 1.7 1997/10/20 02:49:14 mrg Exp $"); int proc_compare(p1, p2) - struct proc *p1, *p2; + struct extern_proc *p1, *p2; { if (p1 == NULL) @@ -123,5 +121,5 @@ proc_compare(p1, p2) 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 */ + return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ } diff --git a/w/uptime.1 b/w/uptime.1 index 69b59bd..a7177a7 100644 --- a/w/uptime.1 +++ b/w/uptime.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -32,17 +30,18 @@ .\" SUCH DAMAGE. .\" .\" @(#)uptime.1 8.2 (Berkeley) 4/18/94 +.\" $FreeBSD: src/usr.bin/w/uptime.1,v 1.7 2001/07/15 08:01:40 dd Exp $ .\" .Dd April 18, 1994 .Dt UPTIME 1 -.Os BSD 3 +.Os .Sh NAME .Nm uptime .Nd show how long system has been running .Sh SYNOPSIS .Nm .Sh DESCRIPTION -The +The .Nm utility displays the current time, the length of time the system has been up, diff --git a/w/w.1 b/w/w.1 index 2229bfc..5bea557 100644 --- a/w/w.1 +++ b/w/w.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -32,19 +30,20 @@ .\" SUCH DAMAGE. .\" .\" @(#)w.1 8.1 (Berkeley) 6/6/93 +.\" $FreeBSD: src/usr.bin/w/w.1,v 1.17 2001/07/26 19:20:13 brian Exp $ .\" .Dd June 6, 1993 .Dt W 1 -.Os BSD 4 +.Os .Sh NAME .Nm w -.Nd "who present users are and what they are doing" +.Nd "display who is logged in and what they are doing" .Sh SYNOPSIS .Nm -.Op Fl hin +.Op Fl dhin .Op Fl M Ar core .Op Fl N Ar system -.Op Ar user +.Op Ar user ... .Sh DESCRIPTION The .Nm @@ -63,6 +62,9 @@ and the name and arguments of the current process. .Pp The options are as follows: .Bl -tag -width Ds +.It Fl d +dumps out the entire process list on a per controlling +tty basis, instead of just the top level process. .It Fl h Suppress the heading. .It Fl i @@ -76,24 +78,24 @@ Extract the name list from the specified system instead of the default .Dq /mach . .It Fl n -Show network addresses as numbers (normally +Don't attempt to resolve network addresses (normally .Nm -interprets addresses and attempts to display them symbolically). +interprets addresses and attempts to display them as names). .El .Pp -If a +If one or more .Ar user -name is specified, the output is restricted to that user. +names are specified, the output is restricted to those users. .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 +.Xr uptime 1 , +.Xr who 1 .Sh BUGS The notion of the .Dq current process @@ -123,7 +125,7 @@ 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 +The .Nm utility does not know about the new conventions for detection of background jobs. @@ -140,4 +142,4 @@ flags are no longer supported. The .Nm command appeared in -.Ux 3.0 . +.Bx 3.0 . diff --git a/w/w.c b/w/w.c index e94fc0f..c27f070 100644 --- a/w/w.c +++ b/w/w.c @@ -1,5 +1,3 @@ -/* $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. @@ -34,18 +32,16 @@ */ #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 */ +static const char copyright[] = +"@(#) Copyright (c) 1980, 1991, 1993, 1994\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif #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 $"); +static const char sccsid[] = "@(#)w.c 8.4 (Berkeley) 4/16/94"; #endif -#endif /* not lint */ /* * w - print system status (who and what) @@ -61,10 +57,12 @@ __RCSID("$NetBSD: w.c,v 1.30 1998/07/06 07:50:20 mrg Exp $"); #include #include #include +#include #include #include #include +#include #include #include @@ -72,14 +70,14 @@ __RCSID("$NetBSD: w.c,v 1.30 1998/07/06 07:50:20 mrg Exp $"); #include #include #include +#include #include #include #include +#include #include #include #include -#include -#include #include #include #include @@ -91,14 +89,15 @@ 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]; +int dflag; /* true if -d flag: output debug info */ +int sortidle; /* sort by idle time */ +int use_ampm; /* use AM/PM time */ +int use_comma; /* use comma as floats separator */ +char **sel_users; /* login array of particular users selected */ /* * One of these per active utmp entry. @@ -106,51 +105,69 @@ char domain[MAXHOSTNAMELEN + 1]; 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 */ + dev_t tdev; /* dev_t of terminal */ + time_t idle; /* idle time of terminal in seconds */ + struct kinfo_proc *kp; /* `most interesting' proc */ + char *args; /* arg list of interesting process */ + struct kinfo_proc *dkp; /* debug option proc list */ } *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 **)); +#define debugproc(p) *((struct kinfo_proc **)&(p)->ki_spare[0]) + +/* W_DISPHOSTSIZE should not be greater than UT_HOSTSIZE */ +#define W_DISPHOSTSIZE 16 + +static void pr_header(time_t *, int); +static struct stat *ttystat(char *, int); +static void usage(int); +static int this_is_uptime(const char *s); +static void w_getargv(void); + +char *fmt_argv(char **, char *, int); /* ../../bin/ps/fmt.c */ int main(argc, argv) int argc; char **argv; { - extern char *__progname; - struct kinfo_proc *kp; - struct hostent *hp; + struct kinfo_proc *kp, *kprocbuf; + struct kinfo_proc *dkp; struct stat *stp; FILE *ut; - struct in_addr l; - int ch, i, nentries, nusers, wcmd; - gid_t egid = getegid(); - char *memf, *nlistf, *p, *x; + time_t touched; + int ch, i, nentries, nusers, wcmd, longidle, dropgid; + const char *memf, *nlistf, *p; + char *x_suffix; char buf[MAXHOSTNAMELEN], errbuf[_POSIX2_LINE_MAX]; - - (void)setegid(getgid()); + char fn[MAXHOSTNAMELEN]; + char *dot; + int local_error = 0, retry_count = 0; + size_t bufSize = 0; + size_t orig_bufSize = 0; + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; + + (void)setlocale(LC_ALL, ""); + /* + use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0'); + use_comma = (*nl_langinfo(RADIXCHAR) != ','); + */ /* Are we w(1) or uptime(1)? */ - p = __progname; - if (*p == '-') - p++; - if (*p == 'u') { + if (this_is_uptime(argv[0]) == 0) { wcmd = 0; p = ""; } else { wcmd = 1; - p = "hiflM:N:nsuw"; + p = "dhiflM:N:nsuw"; } + dropgid = 0; memf = nlistf = NULL; while ((ch = getopt(argc, argv, p)) != -1) switch (ch) { + case 'd': + dflag = 1; + break; case 'h': header = 0; break; @@ -160,9 +177,11 @@ main(argc, argv) case 'M': header = 0; memf = optarg; + dropgid = 1; break; case 'N': nlistf = optarg; + dropgid = 1; break; case 'n': nflag = 1; @@ -177,45 +196,54 @@ main(argc, argv) argc -= optind; argv += optind; + if (!(_res.options & RES_INIT)) + res_init(); + _res.retrans = 2; /* resolver timeout to 2 seconds per try */ + _res.retry = 1; /* only try once.. */ + /* - * 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. + * Discard setgid privileges if not the running kernel so that bad + * guys can't print interesting stuff from kernel memory. */ - if (nlistf != NULL || memf != NULL) - (void)setgid(getgid()); - else - (void)setegid(egid); + if (dropgid) + setgid(getgid()); +#ifdef OLD_PROC if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == NULL) errx(1, "%s", errbuf); - - /* get rid of it now anyway */ - if (nlistf == NULL && memf == NULL) - (void)setgid(getgid()); +#endif (void)time(&now); if ((ut = fopen(_PATH_UTMP, "r")) == NULL) err(1, "%s", _PATH_UTMP); if (*argv) - sel_user = *argv; + sel_users = argv; for (nusers = 0; fread(&utmp, sizeof(utmp), 1, ut);) { if (utmp.ut_name[0] == '\0') continue; + if (!(stp = ttystat(utmp.ut_line, UT_LINESIZE))) + continue; /* corrupted record */ ++nusers; - if (wcmd == 0 || (sel_user && - strncmp(utmp.ut_name, sel_user, UT_NAMESIZE) != 0)) + if (wcmd == 0) continue; + if (sel_users) { + int usermatch; + char **user; + + usermatch = 0; + for (user = sel_users; !usermatch && *user; user++) + if (!strncmp(utmp.ut_name, *user, UT_NAMESIZE)) + usermatch = 1; + if (!usermatch) + continue; + } if ((ep = calloc(1, sizeof(struct entry))) == NULL) - err(1, "%s", ""); + errx(1, "calloc"); *nextp = ep; - nextp = &(ep->next); - memmove(&(ep->utmp), &utmp, sizeof(struct utmp)); - if (!(stp = ttystat(ep->utmp.ut_line))) - continue; + nextp = &ep->next; + memmove(&ep->utmp, &utmp, sizeof(struct utmp)); ep->tdev = stp->st_rdev; #ifdef CPU_CONSDEV /* @@ -229,49 +257,103 @@ main(argc, argv) mib[0] = CTL_MACHDEP; mib[1] = CPU_CONSDEV; size = sizeof(dev_t); - (void) sysctl(mib, 2, &ep->tdev, &size, NULL, 0); + (void)sysctl(mib, 2, &ep->tdev, &size, NULL, 0); } #endif - if ((ep->idle = now - stp->st_atime) < 0) + touched = stp->st_atime; + if (touched < ep->utmp.ut_time) { + /* tty untouched since before login */ + touched = ep->utmp.ut_time; + } + if ((ep->idle = now - touched) < 0) ep->idle = 0; } (void)fclose(ut); if (header || wcmd == 0) { pr_header(&now, nusers); - if (wcmd == 0) - exit (0); - } + if (wcmd == 0) { +#ifdef OLD_PROC + (void)kvm_close(kd); +#endif + exit(0); + } -#define HEADER "USER TTY FROM LOGIN@ IDLE WHAT\n" -#define WUSED (sizeof (HEADER) - sizeof ("WHAT\n")) - (void)printf(HEADER); +#define HEADER_USER "USER" +#define HEADER_TTY "TTY" +#define HEADER_FROM "FROM" +#define HEADER_LOGIN_IDLE "LOGIN@ IDLE " +#define HEADER_WHAT "WHAT\n" +#define WUSED (UT_NAMESIZE + UT_LINESIZE + W_DISPHOSTSIZE + \ + sizeof(HEADER_LOGIN_IDLE) + 3) /* header width incl. spaces */ + (void)printf("%-*.*s %-*.*s %-*.*s %s", + UT_NAMESIZE, UT_NAMESIZE, HEADER_USER, + UT_LINESIZE, UT_LINESIZE, HEADER_TTY, + W_DISPHOSTSIZE, W_DISPHOSTSIZE, HEADER_FROM, + HEADER_LOGIN_IDLE HEADER_WHAT); + } +#ifdef OLD_PROC 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; + err(1, "%s", kvm_geterr(kd)); #else - struct proc *p = &kp->kp_proc; -#endif - struct eproc *e; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_ALL; + mib[3] = 0; + + if (sysctl(mib, 4, NULL, &bufSize, NULL, 0) < 0) { + perror("Failure calling sysctl"); + exit(1); + } - if (p->p_stat == SIDL || p->p_stat == SZOMB) + kprocbuf = kp = (struct kinfo_proc *)malloc(bufSize); + + retry_count = 0; + orig_bufSize = bufSize; + for (retry_count = 0; ; retry_count++) { + local_error = 0; + bufSize = orig_bufSize; + if ((local_error = sysctl(mib, 4, kp, &bufSize, NULL, 0)) < 0) { + if (retry_count < 1000) { + sleep(1); + continue; + } + perror("Failure calling sysctl"); + exit(1); + } else if (local_error == 0) { + break; + } + sleep(1); + } + nentries = bufSize / sizeof(struct kinfo_proc); +#endif + for (i = 0; i < nentries; i++, kp++) { + if (kp->kp_proc.p_stat == SIDL || kp->kp_proc.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) { + if (ep->tdev == kp->kp_eproc.e_tdev) { /* - * Proc is in foreground of this terminal + * proc is associated with 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 (ep->kp == NULL && kp->kp_eproc.e_pgid == kp->kp_eproc.e_tpgid) { + /* + * Proc is 'most interesting' + */ + if (proc_compare(&ep->kp->kp_proc, &kp->kp_proc)) + ep->kp = kp; + } + /* + * Proc debug option info; add to debug + * list using kinfo_proc ki_spare[0] + * as next pointer; ptr to ptr avoids the + * ptr = long assumption. + */ + dkp = ep->dkp; + ep->dkp = kp; +/* --bbraun + debugproc(kp) = dkp; +*/ } } } @@ -284,10 +366,25 @@ main(argc, argv) argwidth = ttywidth - WUSED; if (argwidth < 4) argwidth = 8; + for (ep = ehead; ep != NULL; ep = ep->next) { + if (ep->kp == NULL) { + ep->args = strdup("-"); + continue; + } +#ifdef OLD_PROC + ep->args = fmt_argv(kvm_getargv(kd, ep->kp, argwidth), + ep->kp->kp_proc.p_comm, MAXCOMLEN); +#else + w_getargv(); +#endif + if (ep->args == NULL) + err(1, NULL); + } /* sort by idle time */ if (sortidle && ehead != NULL) { - struct entry *from = ehead, *save; - + struct entry *from, *save; + + from = ehead; ehead = NULL; while (from != NULL) { for (nextp = &ehead; @@ -300,80 +397,99 @@ main(argc, argv) *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'; + char host_buf[UT_HOSTSIZE + 1]; + struct sockaddr_storage ss; + struct sockaddr *sa = (struct sockaddr *)&ss; + struct sockaddr_in *lsin = (struct sockaddr_in *)&ss; +#ifdef SUCKAGE + struct hostent *hp; +#else + struct sockaddr_in6 *lsin6 = (struct sockaddr_in6 *)&ss; +#endif + int isaddr; + + host_buf[UT_HOSTSIZE] = '\0'; + strncpy(host_buf, ep->utmp.ut_host, UT_HOSTSIZE); + p = *host_buf ? host_buf : "-"; + if ((x_suffix = strrchr(p, ':')) != NULL) { + if ((dot = strchr(x_suffix, '.')) != NULL && + strchr(dot+1, '.') == NULL) + *x_suffix++ = '\0'; + else + x_suffix = NULL; + } + if (!nflag) { + /* Attempt to change an IP address into a name */ + isaddr = 0; + memset(&ss, '\0', sizeof(ss)); +#ifdef SUCKAGE + if (inet_aton(p, &lsin->sin_addr) ) { + lsin->sin_len = sizeof(*lsin); + lsin->sin_family = AF_INET; + isaddr = 1; } - p = hp->h_name; + + hp = gethostbyaddr((char *)&lsin->sin_addr, sizeof(lsin->sin_addr), AF_INET); + if( hp ) { + p = hp->h_name; + } +#else + if (inet_pton(AF_INET6, p, &lsin6->sin6_addr) == 1) { + lsin6->sin6_len = sizeof(*lsin6); + lsin6->sin6_family = AF_INET6; + isaddr = 1; + } else if (inet_pton(AF_INET, p, &lsin->sin_addr) == 1) { + lsin->sin_len = sizeof(*lsin); + lsin->sin_family = AF_INET; + isaddr = 1; + } + if (isaddr && realhostname_sa(fn, sizeof(fn), sa, + sa->sa_len) == HOSTNAME_FOUND) + p = fn; +#endif } - if (x) { - (void)snprintf(buf, sizeof(buf), "%s:%.*s", p, - (int)(ep->utmp.ut_host + UT_HOSTSIZE - x), x); + if (x_suffix) { + (void)snprintf(buf, sizeof(buf), "%s:%s", p, x_suffix); p = buf; } - (void)printf("%-*.*s %-2.2s %-*.*s ", +#ifndef SUCKAGE + if (dflag) { + for (dkp = ep->dkp; dkp != NULL; dkp = debugproc(dkp)) { + const char *ptr; + + ptr = fmt_argv(kvm_getargv(kd, dkp, argwidth), + dkp->ki_comm, MAXCOMLEN); + if (ptr == NULL) + ptr = "-"; + (void)printf("\t\t%-9d %s\n", + dkp->ki_pid, ptr); + } + } +#endif + (void)printf("%-*.*s %-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, ep->utmp.ut_name, - strncmp(ep->utmp.ut_line, "tty", 3) ? + UT_LINESIZE, UT_LINESIZE, + strncmp(ep->utmp.ut_line, "tty", 3) && + strncmp(ep->utmp.ut_line, "cua", 3) ? ep->utmp.ut_line : ep->utmp.ut_line + 3, - UT_HOSTSIZE, UT_HOSTSIZE, *p ? p : "-"); + W_DISPHOSTSIZE, W_DISPHOSTSIZE, *p ? p : "-"); pr_attime(&ep->utmp.ut_time, &now); - pr_idle(ep->idle); - pr_args(ep->kp); - printf("\n"); + longidle = pr_idle(ep->idle); + (void)printf("%.*s\n", argwidth - longidle, ep->args); +#ifndef OLD_PROC + free(ep->args); +#endif } +#ifdef OLD_PROC + (void)kvm_close(kd); +#else + free(kprocbuf); +#endif 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; @@ -381,19 +497,16 @@ pr_header(nowp, nusers) { double avenrun[3]; time_t uptime; - int days, hrs, i, mins; + int days, hrs, i, mins, secs; 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)); + (void)strftime(buf, sizeof(buf) - 1, + use_ampm ? "%l:%M%p" : "%k:%M", localtime(nowp)); buf[sizeof(buf) - 1] = '\0'; (void)printf("%s ", buf); @@ -407,32 +520,29 @@ pr_header(nowp, nusers) 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" : ""); - } - } + if (uptime > 60) + uptime += 30; + days = uptime / 86400; + uptime %= 86400; + hrs = uptime / 3600; + uptime %= 3600; + mins = uptime / 60; + secs = uptime % 60; + (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" : ""); + else if (mins > 0) + (void)printf(" %d min%s,", mins, mins > 1 ? "s" : ""); + else + (void)printf(" %d sec%s,", secs, secs > 1 ? "s" : ""); } /* Print number of users logged in to system */ - (void)printf(" %d user%s", nusers, nusers != 1 ? "s" : ""); + (void)printf(" %d user%s", nusers, nusers == 1 ? "" : "s"); /* * Print 1, 5, and 15 minute load averages. @@ -441,8 +551,8 @@ pr_header(nowp, nusers) (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) + for (i = 0; i < (int)(sizeof(avenrun) / sizeof(avenrun[0])); i++) { + if (use_comma && i > 0) (void)printf(","); (void)printf(" %.2f", avenrun[i]); } @@ -451,15 +561,18 @@ pr_header(nowp, nusers) } static struct stat * -ttystat(line) +ttystat(line, sz) char *line; + int sz; { static struct stat sb; char ttybuf[MAXPATHLEN]; - (void)snprintf(ttybuf, sizeof(ttybuf), "%s/%s", _PATH_DEV, line); - if (stat(ttybuf, &sb)) + (void)snprintf(ttybuf, sizeof(ttybuf), "%s%.*s", _PATH_DEV, sz, line); + if (stat(ttybuf, &sb)) { + warn("%s", ttybuf); return (NULL); + } return (&sb); } @@ -469,8 +582,92 @@ usage(wcmd) { if (wcmd) (void)fprintf(stderr, - "usage: w: [-hin] [-M core] [-N system] [user]\n"); + "usage: w [-dhin] [-M core] [-N system] [user ...]\n"); else - (void)fprintf(stderr, "uptime\n"); + (void)fprintf(stderr, "usage: uptime\n"); exit(1); } + +static int +this_is_uptime(s) + const char *s; +{ + const char *u; + + if ((u = strrchr(s, '/')) != NULL) + ++u; + else + u = s; + if (strcmp(u, "uptime") == 0) + return (0); + return (-1); +} + +static void +w_getargv(void) +{ + int mib[3], argmax; + size_t size; + char *procargs, *sp, *np, *cp; + + mib[0] = CTL_KERN; + mib[1] = KERN_ARGMAX; + + size = sizeof(argmax); + if (sysctl(mib, 2, &argmax, &size, NULL, 0) == -1) { + goto ERROR; + } + + procargs = malloc(argmax); + if (procargs == NULL) { + goto ERROR; + } + + mib[0] = CTL_KERN; + mib[1] = KERN_PROCARGS; + mib[2] = KI_PROC(ep)->p_pid; + + size = (size_t)argmax; + if (sysctl(mib, 3, procargs, &size, NULL, 0) == -1) { + goto ERROR_FREE; + } + + for (cp = procargs; cp < &procargs[size]; cp++) { + if (*cp == '\0') { + break; + } + } + if (cp == &procargs[size]) { + goto ERROR_FREE; + } + + sp = cp; + + for (np = NULL; cp < &procargs[size]; cp++) { + if (*cp == '\0') { + if (np != NULL) { + *np = ' '; + } + np = cp; + } else if (*cp == '=') { + break; + } + } + + for (np = sp; (np < &procargs[size]) && (*np == ' '); np++); + + ep->args = strdup(np); + free(procargs); + return; + +ERROR_FREE: + free(procargs); +ERROR: +/* + ep->args = malloc(2); + ep->args[0] = '-'; + ep->args[1] = '\0'; +*/ + asprintf(&ep->args, "%s", KI_PROC(ep)->p_comm); + return; +} diff --git a/which/which.1 b/which/which.1 index 5353cdd..908f7d3 100644 --- a/which/which.1 +++ b/which/which.1 @@ -39,9 +39,7 @@ .Os BSD 3 .Sh NAME .Nm which -.Nd "locate a program file including aliases and paths" -.Pq Xr csh 1 -only) +.Nd "locate a program file in the user's path" .Sh SYNOPSIS .Nm .Op Ar name diff --git a/window/Makefile b/window/Makefile deleted file mode 100644 index 911eed3..0000000 --- a/window/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -# -# 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 = -lcurses -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -NEXTSTEP_PB_CFLAGS = - - -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 deleted file mode 100644 index 013b558..0000000 --- a/window/Makefile.postamble +++ /dev/null @@ -1 +0,0 @@ -include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Postamble.Common diff --git a/window/Makefile.preamble b/window/Makefile.preamble deleted file mode 100644 index 9e10e90..0000000 --- a/window/Makefile.preamble +++ /dev/null @@ -1 +0,0 @@ -include $(CoreOSMakefiles)/ProjectBuilder/Makefile.Preamble.Common diff --git a/window/PB.project b/window/PB.project deleted file mode 100644 index b18adac..0000000 --- a/window/PB.project +++ /dev/null @@ -1,131 +0,0 @@ -{ - 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 deleted file mode 100644 index 42d45b3..0000000 --- a/window/README +++ /dev/null @@ -1,199 +0,0 @@ -/*- - * 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 deleted file mode 100644 index 00928a2..0000000 --- a/window/alias.h +++ /dev/null @@ -1,58 +0,0 @@ -/* $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 deleted file mode 100644 index c7a43a3..0000000 --- a/window/char.c +++ /dev/null @@ -1,157 +0,0 @@ -/* $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 deleted file mode 100644 index 28c1fc5..0000000 --- a/window/char.h +++ /dev/null @@ -1,66 +0,0 @@ -/* $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 deleted file mode 100644 index d0b1bb9..0000000 --- a/window/cmd.c +++ /dev/null @@ -1,316 +0,0 @@ -/* $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 deleted file mode 100644 index f7ed760..0000000 --- a/window/cmd1.c +++ /dev/null @@ -1,182 +0,0 @@ -/* $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 deleted file mode 100644 index 6cffcfc..0000000 --- a/window/cmd2.c +++ /dev/null @@ -1,167 +0,0 @@ -/* $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 deleted file mode 100644 index 4b229c6..0000000 --- a/window/cmd3.c +++ /dev/null @@ -1,74 +0,0 @@ -/* $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 deleted file mode 100644 index b356599..0000000 --- a/window/cmd4.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $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 deleted file mode 100644 index 13f8b6e..0000000 --- a/window/cmd5.c +++ /dev/null @@ -1,142 +0,0 @@ -/* $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 deleted file mode 100644 index dce3343..0000000 --- a/window/cmd6.c +++ /dev/null @@ -1,119 +0,0 @@ -/* $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 deleted file mode 100644 index 5d17623..0000000 --- a/window/cmd7.c +++ /dev/null @@ -1,294 +0,0 @@ -/* $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 deleted file mode 100644 index edc233e..0000000 --- a/window/compress.c +++ /dev/null @@ -1,940 +0,0 @@ -/* $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 deleted file mode 100644 index 4409a69..0000000 --- a/window/context.c +++ /dev/null @@ -1,147 +0,0 @@ -/* $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 deleted file mode 100644 index 0f9b5a0..0000000 --- a/window/context.h +++ /dev/null @@ -1,89 +0,0 @@ -/* $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 deleted file mode 100644 index f1bbb68..0000000 --- a/window/defs.h +++ /dev/null @@ -1,131 +0,0 @@ -/* $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 deleted file mode 100644 index 6c82e23..0000000 --- a/window/error.c +++ /dev/null @@ -1,123 +0,0 @@ -/* $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 deleted file mode 100644 index cad4116..0000000 --- a/window/lcmd.c +++ /dev/null @@ -1,139 +0,0 @@ -/* $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 deleted file mode 100644 index 2741a3e..0000000 --- a/window/lcmd.h +++ /dev/null @@ -1,87 +0,0 @@ -/* $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 deleted file mode 100644 index a856d3d..0000000 --- a/window/lcmd1.c +++ /dev/null @@ -1,466 +0,0 @@ -/* $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 deleted file mode 100644 index 8d8b72b..0000000 --- a/window/lcmd2.c +++ /dev/null @@ -1,408 +0,0 @@ -/* $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 deleted file mode 100644 index 435b5fa..0000000 --- a/window/local.h +++ /dev/null @@ -1,53 +0,0 @@ -/* $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 deleted file mode 100644 index e0f4544..0000000 --- a/window/main.c +++ /dev/null @@ -1,207 +0,0 @@ -/* $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 deleted file mode 100644 index d2848c5..0000000 --- a/window/mloop.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $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 deleted file mode 100644 index e1a8ec5..0000000 --- a/window/parser.h +++ /dev/null @@ -1,65 +0,0 @@ -/* $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 deleted file mode 100644 index b6f2249..0000000 --- a/window/parser1.c +++ /dev/null @@ -1,249 +0,0 @@ -/* $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 deleted file mode 100644 index 963b8b9..0000000 --- a/window/parser2.c +++ /dev/null @@ -1,247 +0,0 @@ -/* $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 deleted file mode 100644 index fd3104e..0000000 --- a/window/parser3.c +++ /dev/null @@ -1,203 +0,0 @@ -/* $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 deleted file mode 100644 index 07782c2..0000000 --- a/window/parser4.c +++ /dev/null @@ -1,307 +0,0 @@ -/* $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 deleted file mode 100644 index 6fcc068..0000000 --- a/window/parser5.c +++ /dev/null @@ -1,211 +0,0 @@ -/* $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 deleted file mode 100644 index ea0ae55..0000000 --- a/window/scanner.c +++ /dev/null @@ -1,598 +0,0 @@ -/* $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 deleted file mode 100644 index 1a23e8b..0000000 --- a/window/startup.c +++ /dev/null @@ -1,104 +0,0 @@ -/* $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 deleted file mode 100644 index 7a59021..0000000 --- a/window/string.c +++ /dev/null @@ -1,165 +0,0 @@ -/* $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 deleted file mode 100644 index aa00223..0000000 --- a/window/token.h +++ /dev/null @@ -1,85 +0,0 @@ -/* $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 deleted file mode 100644 index 1a76912..0000000 --- a/window/tt.h +++ /dev/null @@ -1,183 +0,0 @@ -/* $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[11]; - -/* - * 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 deleted file mode 100644 index b59c57a..0000000 --- a/window/ttf100.c +++ /dev/null @@ -1,77 +0,0 @@ -/* $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 deleted file mode 100644 index e45224e..0000000 --- a/window/ttgeneric.c +++ /dev/null @@ -1,615 +0,0 @@ -/* $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 deleted file mode 100644 index fa16b68..0000000 --- a/window/tth19.c +++ /dev/null @@ -1,322 +0,0 @@ -/* $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 deleted file mode 100644 index 0375cfb..0000000 --- a/window/tth29.c +++ /dev/null @@ -1,105 +0,0 @@ -/* $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 deleted file mode 100644 index f9e2d42..0000000 --- a/window/ttinit.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $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 deleted file mode 100644 index 66cdae2..0000000 --- a/window/ttoutput.c +++ /dev/null @@ -1,157 +0,0 @@ -/* $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 deleted file mode 100644 index 202ce4e..0000000 --- a/window/tttermcap.c +++ /dev/null @@ -1,135 +0,0 @@ -/* $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 deleted file mode 100644 index 1818102..0000000 --- a/window/tttvi925.c +++ /dev/null @@ -1,72 +0,0 @@ -/* $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 deleted file mode 100644 index 3bd7f16..0000000 --- a/window/ttwyse60.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $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 deleted file mode 100644 index 175b215..0000000 --- a/window/ttwyse75.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $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 deleted file mode 100644 index ca0a0f7..0000000 --- a/window/ttzapple.c +++ /dev/null @@ -1,552 +0,0 @@ -/* $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 deleted file mode 100644 index 5907404..0000000 --- a/window/ttzentec.c +++ /dev/null @@ -1,74 +0,0 @@ -/* $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 deleted file mode 100644 index d6b051f..0000000 --- a/window/value.h +++ /dev/null @@ -1,55 +0,0 @@ -/* $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 deleted file mode 100644 index 8fddabc..0000000 --- a/window/var.c +++ /dev/null @@ -1,168 +0,0 @@ -/* $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 deleted file mode 100644 index 2df1087..0000000 --- a/window/var.h +++ /dev/null @@ -1,67 +0,0 @@ -/* $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 deleted file mode 100644 index 830f052..0000000 --- a/window/win.c +++ /dev/null @@ -1,396 +0,0 @@ -/* $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 deleted file mode 100644 index 1f9c1df..0000000 --- a/window/window.1 +++ /dev/null @@ -1,949 +0,0 @@ -.\" $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 deleted file mode 100644 index 4432ad7..0000000 --- a/window/window_string.h +++ /dev/null @@ -1,79 +0,0 @@ -/* $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 deleted file mode 100644 index 57c695a..0000000 --- a/window/windowrc +++ /dev/null @@ -1,85 +0,0 @@ -# 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 deleted file mode 100644 index 9f4799f..0000000 --- a/window/ww.h +++ /dev/null @@ -1,399 +0,0 @@ -/* $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 deleted file mode 100644 index a0311d1..0000000 --- a/window/wwadd.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $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 deleted file mode 100644 index fb7bac5..0000000 --- a/window/wwalloc.c +++ /dev/null @@ -1,82 +0,0 @@ -/* $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 deleted file mode 100644 index 16c0dc5..0000000 --- a/window/wwbox.c +++ /dev/null @@ -1,74 +0,0 @@ -/* $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 deleted file mode 100644 index 53dfd7c..0000000 --- a/window/wwchild.c +++ /dev/null @@ -1,79 +0,0 @@ -/* $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 deleted file mode 100644 index f316db2..0000000 --- a/window/wwclose.c +++ /dev/null @@ -1,69 +0,0 @@ -/* $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 deleted file mode 100644 index 40ef777..0000000 --- a/window/wwclreol.c +++ /dev/null @@ -1,104 +0,0 @@ -/* $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 deleted file mode 100644 index 0059684..0000000 --- a/window/wwclreos.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $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 deleted file mode 100644 index 3367449..0000000 --- a/window/wwcursor.c +++ /dev/null @@ -1,103 +0,0 @@ -/* $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 deleted file mode 100644 index 49b886a..0000000 --- a/window/wwdata.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $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 deleted file mode 100644 index 183b6ec..0000000 --- a/window/wwdelchar.c +++ /dev/null @@ -1,133 +0,0 @@ -/* $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 deleted file mode 100644 index 50d118d..0000000 --- a/window/wwdelete.c +++ /dev/null @@ -1,149 +0,0 @@ -/* $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 deleted file mode 100644 index 351c71f..0000000 --- a/window/wwdelline.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $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 deleted file mode 100644 index ea24c68..0000000 --- a/window/wwdump.c +++ /dev/null @@ -1,128 +0,0 @@ -/* $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 deleted file mode 100644 index 2431d70..0000000 --- a/window/wwend.c +++ /dev/null @@ -1,75 +0,0 @@ -/* $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 deleted file mode 100644 index d033e3d..0000000 --- a/window/wwenviron.c +++ /dev/null @@ -1,117 +0,0 @@ -/* $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 deleted file mode 100644 index ed20f09..0000000 --- a/window/wwerror.c +++ /dev/null @@ -1,75 +0,0 @@ -/* $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 deleted file mode 100644 index 64dca64..0000000 --- a/window/wwflush.c +++ /dev/null @@ -1,127 +0,0 @@ -/* $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 deleted file mode 100644 index 13f0dfa..0000000 --- a/window/wwframe.c +++ /dev/null @@ -1,255 +0,0 @@ -/* $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 deleted file mode 100644 index ce0e9ea..0000000 --- a/window/wwgets.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $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 deleted file mode 100644 index bb8f505..0000000 --- a/window/wwinit.c +++ /dev/null @@ -1,425 +0,0 @@ -/* $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 deleted file mode 100644 index 64a117c..0000000 --- a/window/wwinschar.c +++ /dev/null @@ -1,140 +0,0 @@ -/* $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 deleted file mode 100644 index ba749f5..0000000 --- a/window/wwinsline.c +++ /dev/null @@ -1,96 +0,0 @@ -/* $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 deleted file mode 100644 index 4bcc559..0000000 --- a/window/wwiomux.c +++ /dev/null @@ -1,209 +0,0 @@ -/* $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 deleted file mode 100644 index 345a0f0..0000000 --- a/window/wwlabel.c +++ /dev/null @@ -1,106 +0,0 @@ -/* $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 deleted file mode 100644 index cd74614..0000000 --- a/window/wwmisc.c +++ /dev/null @@ -1,76 +0,0 @@ -/* $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 deleted file mode 100644 index 23a5566..0000000 --- a/window/wwmove.c +++ /dev/null @@ -1,107 +0,0 @@ -/* $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 deleted file mode 100644 index 9753cde..0000000 --- a/window/wwopen.c +++ /dev/null @@ -1,206 +0,0 @@ -/* $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 deleted file mode 100644 index d93f1e5..0000000 --- a/window/wwprintf.c +++ /dev/null @@ -1,80 +0,0 @@ -/* $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 deleted file mode 100644 index 1b60204..0000000 --- a/window/wwpty.c +++ /dev/null @@ -1,97 +0,0 @@ -/* $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 deleted file mode 100644 index af7e578..0000000 --- a/window/wwputc.c +++ /dev/null @@ -1,56 +0,0 @@ -/* $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 deleted file mode 100644 index 793e15e..0000000 --- a/window/wwputs.c +++ /dev/null @@ -1,60 +0,0 @@ -/* $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 deleted file mode 100644 index 49bbc62..0000000 --- a/window/wwredraw.c +++ /dev/null @@ -1,65 +0,0 @@ -/* $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 deleted file mode 100644 index 7ed8d92..0000000 --- a/window/wwredrawwin.c +++ /dev/null @@ -1,81 +0,0 @@ -/* $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 deleted file mode 100644 index 929dc4a..0000000 --- a/window/wwrint.c +++ /dev/null @@ -1,87 +0,0 @@ -/* $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 deleted file mode 100644 index 0ac8342..0000000 --- a/window/wwscroll.c +++ /dev/null @@ -1,244 +0,0 @@ -/* $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 deleted file mode 100644 index 1b146d7..0000000 --- a/window/wwsize.c +++ /dev/null @@ -1,201 +0,0 @@ -/* $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 deleted file mode 100644 index 2fd6382..0000000 --- a/window/wwspawn.c +++ /dev/null @@ -1,103 +0,0 @@ -/* $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 deleted file mode 100644 index 10518b5..0000000 --- a/window/wwsuspend.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $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 deleted file mode 100644 index 10f9b37..0000000 --- a/window/wwterminfo.c +++ /dev/null @@ -1,127 +0,0 @@ -/* $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 deleted file mode 100644 index 946b423..0000000 --- a/window/wwtty.c +++ /dev/null @@ -1,195 +0,0 @@ -/* $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 deleted file mode 100644 index f50de75..0000000 --- a/window/wwunframe.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $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 deleted file mode 100644 index a1dbe7a..0000000 --- a/window/wwupdate.c +++ /dev/null @@ -1,281 +0,0 @@ -/* $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 deleted file mode 100644 index 2ef9f9f..0000000 --- a/window/wwwrite.c +++ /dev/null @@ -1,313 +0,0 @@ -/* $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 deleted file mode 100644 index 56459b6..0000000 --- a/window/xx.c +++ /dev/null @@ -1,287 +0,0 @@ -/* $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 deleted file mode 100644 index 56a0103..0000000 --- a/window/xx.h +++ /dev/null @@ -1,81 +0,0 @@ -/* $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 deleted file mode 100644 index 41c8d65..0000000 --- a/window/xxflush.c +++ /dev/null @@ -1,205 +0,0 @@ -/* $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 index 42b5920..174730e 100644 --- a/xargs/Makefile +++ b/xargs/Makefile @@ -14,7 +14,7 @@ PROJECT_TYPE = Tool HFILES = pathnames.h -CFILES = xargs.c +CFILES = xargs.c strnsubst.c OTHERSRCS = Makefile Makefile.preamble Makefile.postamble xargs.1 diff --git a/xargs/PB.project b/xargs/PB.project index 47a0e8c..8e81430 100644 --- a/xargs/PB.project +++ b/xargs/PB.project @@ -3,7 +3,7 @@ FILESTABLE = { FRAMEWORKS = (); H_FILES = (pathnames.h); - OTHER_LINKED = (xargs.c); + OTHER_LINKED = (xargs.c, strnsubst.c); OTHER_SOURCES = (Makefile, Makefile.preamble, Makefile.postamble, xargs.1); SUBPROJECTS = (); }; diff --git a/xargs/strnsubst.c b/xargs/strnsubst.c new file mode 100644 index 0000000..fa8d933 --- /dev/null +++ b/xargs/strnsubst.c @@ -0,0 +1,99 @@ +/* $xMach: strnsubst.c,v 1.3 2002/02/23 02:10:24 jmallett Exp $ */ + +/* + * Copyright (c) 2002 J. Mallett. All rights reserved. + * You may do whatever you want with this file as long as + * the above copyright and this notice remain intact, along + * with the following statement: + * For the man who taught me vi, and who got too old, too young. + */ + +#include +__RCSID("$FreeBSD: src/usr.bin/xargs/strnsubst.c,v 1.6 2002/06/22 12:58:42 jmallett Exp $"); + +#include +#include +#include +#include + +void strnsubst(char **, const char *, const char *, size_t); + +/* + * Replaces str with a string consisting of str with match replaced with + * replstr as many times as can be done before the constructed string is + * maxsize bytes large. It does not free the string pointed to by str, it + * is up to the calling program to be sure that the original contents of + * str as well as the new contents are handled in an appropriate manner. + * If replstr is NULL, then that internally is changed to a nil-string, so + * that we can still pretend to do somewhat meaningful substitution. + * No value is returned. + */ +void +strnsubst(char **str, const char *match, const char *replstr, size_t maxsize) +{ + char *s1, *s2, *this; + + s1 = *str; + if (s1 == NULL) + return; + s2 = calloc(maxsize, 1); + if (s2 == NULL) + err(1, "calloc"); + + if (replstr == NULL) + replstr = ""; + + if (match == NULL || replstr == NULL || maxsize == strlen(s1)) { + strncpy(s2, s1, maxsize); + s2[maxsize - 1] = '\0'; + goto done; + } + + for (;;) { + this = strstr(s1, match); + if (this == NULL) + break; + if ((strlen(s2) + ((uintptr_t)this - (uintptr_t)s1) + + (strlen(replstr) - 1)) > maxsize && *replstr != '\0') { + strncat(s2, s1, maxsize); + s2[maxsize - 1] = '\0'; + goto done; + } + strncat(s2, s1, (uintptr_t)this - (uintptr_t)s1); + strcat(s2, replstr); + s1 = this + strlen(match); + } + strcat(s2, s1); +done: + *str = s2; + return; +} + +#ifdef TEST +#include + +int +main(void) +{ + char *x, *y, *z, *za; + + x = "{}%$"; + strnsubst(&x, "%$", "{} enpury!", 255); + y = x; + strnsubst(&y, "}{}", "ybir", 255); + z = y; + strnsubst(&z, "{", "v ", 255); + za = z; + strnsubst(&z, NULL, za, 255); + if (strcmp(z, "v ybir enpury!") == 0) + printf("strnsubst() seems to work!\n"); + else + printf("strnsubst() is broken.\n"); + printf("%s\n", z); + free(x); + free(y); + free(z); + free(za); + return 0; +} +#endif diff --git a/xargs/xargs.1 b/xargs/xargs.1 index cdff51a..9db9a3f 100644 --- a/xargs/xargs.1 +++ b/xargs/xargs.1 @@ -1,5 +1,3 @@ -.\" $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. .\" @@ -36,8 +34,10 @@ .\" SUCH DAMAGE. .\" .\" @(#)xargs.1 8.1 (Berkeley) 6/6/93 +.\" $FreeBSD: src/usr.bin/xargs/xargs.1,v 1.23 2002/06/22 12:47:56 jmallett Exp $ +.\" $xMach: xargs.1,v 1.2 2002/02/23 05:23:37 tim Exp $ .\" -.Dd June 6, 1993 +.Dd May 7, 2001 .Dt XARGS 1 .Os .Sh NAME @@ -45,13 +45,20 @@ .Nd "construct argument list(s) and execute utility" .Sh SYNOPSIS .Nm -.Op Fl 0 -.Op Fl t -.Oo Op Fl x +.Op Fl 0pt +.Op Fl E Ar eofstr +.Oo +.Fl I Ar replstr +.Op Fl R Ar replacements +.Oc +.Op Fl J Ar replstr +.Op Fl L Ar number +.Oo .Fl n Ar number +.Op Fl x .Oc .Op Fl s Ar size -.Op Ar utility Op Ar arguments ... +.Op Ar utility Op Ar argument ... .Sh DESCRIPTION The .Nm @@ -80,15 +87,92 @@ 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 +.Bl -tag -width indent .It Fl 0 -Use NUL -(``\e0'') -instead of whitespace as the argument separator. -This can be used in conjuction with the +Change +.Nm +to expect NUL +(``\\0'') +characters as separators, instead of spaces and newlines. +This is expected to be used in concert with the .Fl print0 -option of +function in .Xr find 1 . +.It Fl E Ar eofstr +Use +.Ar eofstr +as a logical EOF marker. +.It Fl I Ar replstr +Execute +.Ar utility +for each input line, replacing one or more occurences of +.Ar replstr +in up to +.Ar replacements +(or 5 if no +.Fl R +flag is specified) arguments to +.Ar utility +with the entire line of input. +The resulting arguments, after replacement is done, will not be allowed to grow +beyond 255 bytes; this is implemented by concatenating as much of the argument +containing +.Ar replstr +as possible, to the constructed arguments to +.Ar utility , +up to 255 bytes. +The 255 byte limit does not apply to arguments to +.Ar utility +which do not contain +.Ar replstr , +and furthermore, no replacement will be done on +.Ar utility +itself. +Implies +.Fl x . +.It Fl J Ar replstr +If this option is specified, +.Nm +will use the data read from standard input to replace the first occurrence of +.Ar replstr +instead of appending that data after all other arguments. +This option will not effect how many arguments will be read from input +.Pq Fl n , +or the size of the command(s) +.Nm +will generate +.Pq Fl s . +The option just moves where those arguments will be placed in the command(s) +that are executed. +The +.Ar replstr +must show up as a distinct +.Ar argument +to +.Nm . +It will not be recognized if, for instance, it is in the middle of a +quoted string. +Furthermore, only the first occurrence of the +.Ar replstr +will be replaced. +For example, the following command will copy the list of files and +directories which start with an uppercase letter in the current +directory to +.Pa destdir : +.Pp +.Dl /bin/ls -1d [A-Z]* | xargs -J % cp -rp % destdir +.Pp +.It Fl L Ar number +Call +.Ar utility +for every +.Ar number +lines read. +If EOF is reached and fewer lines have been read than +.Ar number +then +.Ar utility +will be called with the available lines. .It Fl n Ar number Set the maximum number of arguments taken from standard input for each invocation of the utility. @@ -107,19 +191,33 @@ arguments remaining for the last invocation of The current default value for .Ar number is 5000. +.It Fl p +Echo each command to be executed and ask the user whether it should be +executed. +An affirmative response, +.Ql y +in the POSIX locale, +causes the command to be executed, any other response causes it to be +skipped. +No commands are executed if the process is not attached to a terminal. +.It Fl R Ar replacements +Specify the maximum number of arguments that +.Fl I +will do replacement in. .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 +The sum of the length of the utility name, the arguments passed to .Ar utility (including .Dv NULL -terminators) will be less than or equal to this number. +terminators) and the current environment will be less than or equal to +this number. The current default value for .Ar size is .Dv ARG_MAX -- 2048. +- 4096. .It Fl t Echo the command to be executed to standard error immediately before it is executed. @@ -149,44 +247,47 @@ command line cannot be assembled, 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 +.Nm +utility exits with a value of 0 if no error occurs. +If .Ar utility -was found but could not be invoked. -.It 127 -The +cannot be found, +.Nm +exits with a value of 127, otherwise if .Ar utility -could not be found. -.It 1 -Some other error occurred. -.El +cannot be executed, +.Nm +exits with a value of 126. +If any other error occurs, +.Nm +exits with a value of 1. .Sh SEE ALSO .Xr echo 1 , -.Xr find 1 +.Xr find 1 , +.Xr execvp 3 .Sh STANDARDS The .Nm utility is expected to be .St -p1003.2 compliant. +The +.Fl J +and +.Fl R +options are non-standard +.Fx +extensions which may not be available on other operating systems. .Sh HISTORY -The meaning of 123, 124, and 125 exit values were taken from GNU xargs. +The +.Nm +command appeared in PWB UNIX. +.Sh BUGS +If +.Ar utility +attempts to invoke another command such that the number of arguments or the +size of the environment is increased, it risks +.Xr execvp 3 +failing with +.Er E2BIG . diff --git a/xargs/xargs.c b/xargs/xargs.c index 81a0d9a..ed3eba7 100644 --- a/xargs/xargs.c +++ b/xargs/xargs.c @@ -1,5 +1,3 @@ -/* $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. @@ -34,51 +32,67 @@ * 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. + * + * $xMach: xargs.c,v 1.6 2002/02/23 05:27:47 tim Exp $ */ -#include #ifndef lint -__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"); +static const char copyright[] = +"@(#) Copyright (c) 1990, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ -#ifndef lint #if 0 +#ifndef lint 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 */ +#endif + +#include +__RCSID("$FreeBSD: src/usr.bin/xargs/xargs.c,v 1.41 2002/07/01 03:21:05 tjr Exp $"); #include #include + +#include #include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include + #include "pathnames.h" -int tflag, zflag, rval; +static void parse_input(int, char *[]); +static void prerun(int, char *[]); +static int prompt(void); +static void run(char **); +static void usage(void); +void strnsubst(char **, const char *, const char *, size_t); + +static char echo[] = _PATH_ECHO; +static char **av, **bxp, **ep, **exp, **xp; +static char *argp, *bbp, *ebp, *inpline, *p, *replstr; +static const char *eofstr; +static int count, insingle, indouble, pflag, tflag, Rflag, rval, zflag; +static int cnt, Iflag, jfound, Lflag, wasquoted, xflag; -void run __P((char **)); -int main __P((int, char **)); -void usage __P((void)); +extern char **environ; int -main(argc, argv) - int argc; - char **argv; +main(int argc, char *argv[]) { - int ch; - char *p, *bbp, *ebp, **bxp, **exp, **xp; - int cnt, indouble, insingle, nargs, nflag, nline, xflag; - char **av, *argp; + long arg_max; + int ch, Jflag, nargs, nflag, nline; + size_t linelen; - setlocale(LC_ALL, ""); + inpline = replstr = NULL; + ep = environ; + eofstr = ""; + Jflag = nflag = 0; /* * POSIX.2 limits the exec line length to ARG_MAX - 2K. Running that @@ -94,18 +108,44 @@ main(argc, argv) * probably not worthwhile. */ nargs = 5000; - nline = ARG_MAX - 4 * 1024; - nflag = xflag = 0; - while ((ch = getopt(argc, argv, "0n:s:tx")) != -1) + if ((arg_max = sysconf(_SC_ARG_MAX)) == -1) + errx(1, "sysconf(_SC_ARG_MAX) failed"); + nline = arg_max - 4 * 1024; + while (*ep != NULL) { + /* 1 byte for each '\0' */ + nline -= strlen(*ep++) + 1 + sizeof(*ep); + } + while ((ch = getopt(argc, argv, "0E:I:J:L:n:pR:s:tx")) != -1) switch(ch) { - case '0': - zflag = 1; + case 'E': + eofstr = optarg; + break; + case 'I': + Jflag = 0; + Iflag = 1; + Lflag = 1; + replstr = optarg; + break; + case 'J': + Iflag = 0; + Jflag = 1; + replstr = optarg; + break; + case 'L': + Lflag = atoi(optarg); break; case 'n': nflag = 1; if ((nargs = atoi(optarg)) <= 0) errx(1, "illegal argument count"); break; + case 'p': + pflag = 1; + break; + case 'R': + if ((Rflag = atoi(optarg)) <= 0) + errx(1, "illegal number of replacements"); + break; case 's': nline = atoi(optarg); break; @@ -115,6 +155,9 @@ main(argc, argv) case 'x': xflag = 1; break; + case '0': + zflag = 1; + break; case '?': default: usage(); @@ -122,30 +165,45 @@ main(argc, argv) argc -= optind; argv += optind; + if (!Iflag && Rflag) + usage(); + if (Iflag && !Rflag) + Rflag = 5; if (xflag && !nflag) usage(); + if (Iflag || Lflag) + xflag = 1; + if (replstr != NULL && *replstr == '\0') + errx(1, "replstr may not be empty"); /* * 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"); + linelen = 1 + argc + nargs + 1; + if ((av = bxp = malloc(linelen * sizeof(char **))) == NULL) + errx(1, "malloc failed"); /* * 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); + if (*argv == NULL) + cnt = strlen(*bxp++ = echo); else { - cnt = 0; do { + if (Jflag && strcmp(*argv, replstr) == 0) { + char **avj; + jfound = 1; + argv++; + for (avj = argv; *avj; avj++) + cnt += strlen(*avj) + 1; + break; + } cnt += strlen(*bxp++ = *argv) + 1; - } while (*++argv); + } while (*++argv != NULL); } /* @@ -167,178 +225,334 @@ main(argc, argv) if (nline <= 0) errx(1, "insufficient space for command"); - if (!(bbp = malloc((u_int)nline + 1))) - err(1, "malloc"); + if ((bbp = malloc((size_t)(nline + 1))) == NULL) + errx(1, "malloc failed"); ebp = (argp = p = bbp) + nline - 1; + for (;;) + parse_input(argc, argv); +} - for (insingle = indouble = 0;;) - switch(ch = getchar()) { - case EOF: - /* No arguments since last exec. */ - if (p == bbp) - exit(rval); +static void +parse_input(int argc, char *argv[]) +{ + int ch, foundeof; + char **avj; - /* 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; + foundeof = 0; + + switch(ch = getchar()) { + case EOF: + /* No arguments since last exec. */ + if (p == bbp) + 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; - case '\0': - if (zflag) - goto arg2; + goto addch; + case '\n': + count++; + if (zflag) 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'; + + /* Quotes do not escape newlines. */ +arg1: if (insingle || indouble) + errx(1, "unterminated quote"); +arg2: + foundeof = *eofstr != '\0' && + strcmp(argp, eofstr) == 0; + + /* Do not make empty args unless they are quoted */ + if ((argp != p || wasquoted) && !foundeof) { + *p++ = '\0'; *xp++ = argp; + if (Iflag) { + size_t curlen; - /* - * 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 (inpline == NULL) + curlen = 0; + else { + /* + * If this string is not zero + * length, append a space for + * seperation before the next + * argument. + */ + if ((curlen = strlen(inpline))) + strcat(inpline, " "); + } + curlen++; + /* + * Allocate enough to hold what we will + * be holding in a second, and to append + * a space next time through, if we have + * to. + */ + inpline = realloc(inpline, curlen + 2 + + strlen(argp)); + if (inpline == NULL) + errx(1, "realloc failed"); + if (curlen == 1) + strcpy(inpline, argp); + else + strcat(inpline, argp); } + } - /* 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) + /* + * 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. Having reached the limit + * of input lines, as specified by -L is the same as + * maxing out on arguments. + */ + if (xp == exp || p > ebp || ch == EOF || + (Lflag <= count && xflag) || foundeof) { + if (xflag && xp != exp && p > ebp) errx(1, "insufficient space for arguments"); - - *xp = NULL; - run(av); + if (jfound) { + for (avj = argv; *avj; avj++) + *xp++ = *avj; + } + prerun(argc, av); + if (ch == EOF || foundeof) + exit(rval); + p = bbp; xp = bxp; - cnt = ebp - argp; - memmove(bbp, argp, cnt); - p = (argp = bbp) + cnt; + count = 0; + } + argp = p; + wasquoted = 0; + break; + case '\'': + if (indouble || zflag) + goto addch; + insingle = !insingle; + wasquoted = 1; + break; + case '"': + if (insingle || zflag) + goto addch; + indouble = !indouble; + wasquoted = 1; + 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; } - /* NOTREACHED */ + + /* 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"); + + if (jfound) { + for (avj = argv; *avj; avj++) + *xp++ = *avj; + } + prerun(argc, av); + xp = bxp; + cnt = ebp - argp; + memcpy(bbp, argp, (size_t)cnt); + p = (argp = bbp) + cnt; + *p++ = ch; + break; + } + return; } -void -run(argv) - char **argv; +/* + * Do things necessary before run()'ing, such as -I substitution, + * and then call run(). + */ +static void +prerun(int argc, char *argv[]) { - volatile int noinvoke; - char **p; + char **tmp, **tmp2, **avj; + int repls; + + repls = Rflag; + + if (argc == 0 || repls == 0) { + *xp = NULL; + run(argv); + return; + } + + avj = argv; + + /* + * Allocate memory to hold the argument list, and + * a NULL at the tail. + */ + tmp = malloc((argc + 1) * sizeof(char**)); + if (tmp == NULL) + errx(1, "malloc failed"); + tmp2 = tmp; + + /* + * Save the first argument and iterate over it, we + * cannot do strnsubst() to it. + */ + if ((*tmp++ = strdup(*avj++)) == NULL) + errx(1, "strdup failed"); + + /* + * For each argument to utility, if we have not used up + * the number of replacements we are allowed to do, and + * if the argument contains at least one occurance of + * replstr, call strnsubst(), else just save the string. + * Iterations over elements of avj and tmp are done + * where appropriate. + */ + while (--argc) { + *tmp = *avj++; + if (repls && strstr(*tmp, replstr) != NULL) { + strnsubst(tmp++, replstr, inpline, (size_t)255); + repls--; + } else { + if ((*tmp = strdup(*tmp)) == NULL) + errx(1, "strdup failed"); + tmp++; + } + } + + /* + * Run it. + */ + *tmp = NULL; + run(tmp2); + + /* + * Walk from the tail to the head, free along the way. + */ + for (; tmp2 != tmp; tmp--) + free(*tmp); + /* + * Now free the list itself. + */ + free(tmp2); + + /* + * Free the input line buffer, if we have one. + */ + if (inpline != NULL) { + free(inpline); + inpline = NULL; + } +} + +static void +run(char **argv) +{ + volatile int childerr; + char **avec; pid_t pid; int status; - if (tflag) { + /* + * If the user wants to be notified of each command before it is + * executed, notify them. If they want the notification to be + * followed by a prompt, then prompt them. + */ + if (tflag || pflag) { (void)fprintf(stderr, "%s", *argv); - for (p = argv + 1; *p; ++p) - (void)fprintf(stderr, " %s", *p); + for (avec = argv + 1; *avec != NULL; ++avec) + (void)fprintf(stderr, " %s", *avec); + /* + * If the user has asked to be prompted, do so. + */ + if (pflag) + /* + * If they asked not to exec, return without execution + * but if they asked to, go to the execution. If we + * could not open their tty, break the switch and drop + * back to -t behaviour. + */ + switch (prompt()) { + case 0: + return; + case 1: + goto exec; + case 2: + break; + } (void)fprintf(stderr, "\n"); (void)fflush(stderr); } - noinvoke = 0; +exec: + childerr = 0; switch(pid = vfork()) { case -1: err(1, "vfork"); case 0: execvp(argv[0], argv); - noinvoke = (errno == ENOENT) ? 127 : 126; - warn("%s", argv[0]);; + childerr = errno; _exit(1); } pid = waitpid(pid, &status, 0); if (pid == -1) err(1, "waitpid"); + /* If we couldn't invoke the utility, exit. */ + if (childerr != 0) + err(childerr == ENOENT ? 127 : 126, "%s", *argv); + /* If utility signaled or exited with a value of 255, exit 1-125. */ + if (WIFSIGNALED(status) || WEXITSTATUS(status) == 255) + exit(1); + if (WEXITSTATUS(status)) + rval = 1; +} - /* - * If we couldn't invoke the utility or the utility didn't exit - * properly, quit with 127 or 126 respectively. - */ - if (noinvoke) - exit(noinvoke); +/* + * Prompt the user about running a command. + */ +static int +prompt(void) +{ + regex_t cre; + size_t rsize; + int match; + char *response; + FILE *ttyfp; - /* - * 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); + if ((ttyfp = fopen(_PATH_TTY, "r")) == NULL) + return (2); /* Indicate that the TTY failed to open. */ + (void)fprintf(stderr, "?..."); + (void)fflush(stderr); + if ((response = fgetln(ttyfp, &rsize)) == NULL || + regcomp(&cre, + "^[yY]", + REG_BASIC) != 0) { + (void)fclose(ttyfp); + return (0); } + match = regexec(&cre, response, 0, NULL, 0); + (void)fclose(ttyfp); + regfree(&cre); + return (match == 0); } -void -usage() +static void +usage(void) { - (void)fprintf(stderr, -"usage: xargs [-0t] [-n number [-x]] [-s size] [utility [argument ...]]\n"); + fprintf(stderr, +"usage: xargs [-0pt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]\n" +" [-L number] [-n number [-x] [-s size] [utility [argument ...]]\n"); exit(1); } -- 2.45.2