diff options
Diffstat (limited to 'usr.bin/vi/options.c')
-rw-r--r-- | usr.bin/vi/options.c | 142 |
1 files changed, 88 insertions, 54 deletions
diff --git a/usr.bin/vi/options.c b/usr.bin/vi/options.c index 9c74160c5c01..b4301a228460 100644 --- a/usr.bin/vi/options.c +++ b/usr.bin/vi/options.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1991, 1993 + * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,27 +32,36 @@ */ #ifndef lint -static char sccsid[] = "@(#)options.c 8.36 (Berkeley) 12/29/93"; +static char sccsid[] = "@(#)options.c 8.52 (Berkeley) 3/24/94"; #endif /* not lint */ #include <sys/types.h> +#include <queue.h> #include <sys/stat.h> +#include <sys/time.h> +#include <bitstring.h> #include <ctype.h> -#include <curses.h> #include <errno.h> +#include <limits.h> +#include <signal.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <termios.h> #include <unistd.h> +#include <db.h> +#include <regex.h> +#include <pathnames.h> + #include "vi.h" #include "excmd.h" -#include "pathnames.h" static int opts_abbcmp __P((const void *, const void *)); static int opts_cmp __P((const void *, const void *)); static OPTLIST const *opts_prefix __P((char *)); -static int opts_print __P((SCR *, OPTLIST const *, OPTION *)); +static int opts_print __P((SCR *, OPTLIST const *)); /* * O'Reilly noted options and abbreviations are from "Learning the VI Editor", @@ -73,6 +82,8 @@ static OPTLIST const optlist[] = { {"autowrite", NULL, OPT_0BOOL, 0}, /* O_BEAUTIFY 4BSD */ {"beautify", NULL, OPT_0BOOL, 0}, +/* O_CDPATH 4.4BSD */ + {"cdpath", f_cdpath, OPT_STR, 0}, /* O_COLUMNS 4.4BSD */ {"columns", f_columns, OPT_NUM, OPT_NOSAVE}, /* O_COMMENT 4.4BSD */ @@ -102,7 +113,12 @@ static OPTLIST const optlist[] = { /* O_LINES 4.4BSD */ {"lines", f_lines, OPT_NUM, OPT_NOSAVE}, /* O_LISP 4BSD */ - {"lisp", f_lisp, OPT_0BOOL, 0}, +/* + * XXX + * When the lisp option is implemented, delete + * the OPT_NOSAVE flag, so that :mkexrc dumps it. + */ + {"lisp", f_lisp, OPT_0BOOL, OPT_NOSAVE}, /* O_LIST 4BSD */ {"list", f_list, OPT_0BOOL, 0}, /* O_MAGIC 4BSD */ @@ -118,7 +134,7 @@ static OPTLIST const optlist[] = { /* O_OPEN 4BSD */ {"open", NULL, OPT_1BOOL, 0}, /* O_OPTIMIZE 4BSD */ - {"optimize", f_optimize, OPT_1BOOL, 0}, + {"optimize", NULL, OPT_1BOOL, 0}, /* O_PARAGRAPHS 4BSD */ {"paragraphs", f_paragraph, OPT_STR, 0}, /* O_PROMPT 4BSD */ @@ -131,6 +147,8 @@ static OPTLIST const optlist[] = { {"redraw", NULL, OPT_0BOOL, 0}, /* O_REMAP 4BSD */ {"remap", NULL, OPT_1BOOL, 0}, +/* O_REMAPMAX 4.4BSD */ + {"remapmax", NULL, OPT_1BOOL, 0}, /* O_REPORT 4BSD */ {"report", NULL, OPT_NUM, OPT_NOSTR}, /* O_RULER 4.4BSD */ @@ -172,11 +190,11 @@ static OPTLIST const optlist[] = { /* O_VERBOSE 4.4BSD */ {"verbose", NULL, OPT_0BOOL, 0}, /* O_W1200 4BSD */ - {"w1200", f_w1200, OPT_NUM, OPT_NEVER}, + {"w1200", f_w1200, OPT_NUM, OPT_NEVER|OPT_NOSAVE}, /* O_W300 4BSD */ - {"w300", f_w300, OPT_NUM, OPT_NEVER}, + {"w300", f_w300, OPT_NUM, OPT_NEVER|OPT_NOSAVE}, /* O_W9600 4BSD */ - {"w9600", f_w9600, OPT_NUM, OPT_NEVER}, + {"w9600", f_w9600, OPT_NUM, OPT_NEVER|OPT_NOSAVE}, /* O_WARN 4BSD */ {"warn", NULL, OPT_1BOOL, 0}, /* O_WINDOW 4BSD */ @@ -273,7 +291,11 @@ opts_init(sp) O_CLR(sp, cnt); else if (op->type == OPT_1BOOL) O_SET(sp, cnt); - + + (void)snprintf(b1, sizeof(b1), "cdpath=%s", + (s = getenv("CDPATH")) == NULL ? ":" : s); + SET_DEF(O_CDPATH, b1); + /* * !!! * Vi historically stored temporary files in /var/tmp. We store them @@ -293,16 +315,16 @@ opts_init(sp) (void)snprintf(b1, sizeof(b1), "scroll=%ld", O_VAL(sp, O_LINES) / 2); SET_DEF(O_SCROLL, b1); SET_DEF(O_SECTIONS, "sections=NHSHH HUnhsh"); - (void)snprintf(b1, sizeof(b1), - "shell=%s", (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s); + (void)snprintf(b1, sizeof(b1), "shell=%s", + (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s); SET_DEF(O_SHELL, b1); SET_DEF(O_SHIFTWIDTH, "shiftwidth=8"); SET_DEF(O_SIDESCROLL, "sidescroll=16"); SET_DEF(O_TABSTOP, "tabstop=8"); (void)snprintf(b1, sizeof(b1), "tags=%s", _PATH_TAGS); SET_DEF(O_TAGS, b1); - (void)snprintf(b1, sizeof(b1), - "term=%s", (s = getenv("TERM")) == NULL ? "unknown" : s); + (void)snprintf(b1, sizeof(b1), "term=%s", + (s = getenv("TERM")) == NULL ? "unknown" : s); SET_DEF(O_TERM, b1); /* @@ -348,7 +370,7 @@ opts_set(sp, argv) u_long value, turnoff; int ch, offset, rval; char *endp, *equals, *name, *p; - + disp = NO_DISPLAY; for (rval = 0; (*argv)->len != 0; ++argv) { /* @@ -359,10 +381,11 @@ opts_set(sp, argv) disp = ALL_DISPLAY; continue; } - + /* Find equals sign or end of set, skipping backquoted chars. */ - for (p = name = argv[0]->bp, equals = NULL; ch = *p; ++p) - switch(ch) { + for (equals = NULL, + p = name = argv[0]->bp; (ch = *p) != '\0'; ++p) + switch (ch) { case '=': equals = p; break; @@ -525,7 +548,7 @@ change: if (sp->s_optchange != NULL) abort(); } } - if (disp) + if (disp != NO_DISPLAY) opts_dump(sp, disp); return (rval); } @@ -546,31 +569,41 @@ opts_dump(sp, type) char nbuf[20]; /* + * XXX + * It's possible to get here by putting "set option" in the + * .exrc file. I can't think of a clean way to layer this, + * or a reasonable check to make, so we block it here. + */ + if (sp->stdfp == NULL) { + msgq(sp, M_ERR, + "Option display requires that the screen be initialized."); + return; + } + + /* * Options are output in two groups -- those that fit in a column and * those that don't. Output is done on 6 character "tab" boundaries * for no particular reason. (Since we don't output tab characters, * we can ignore the terminal's tab settings.) Ignore the user's tab * setting because we have no idea how reasonable it is. + * + * Find a column width we can live with. */ -#define BOUND 6 - - /* Find a column width we can live with. */ for (cnt = 6; cnt > 1; --cnt) { - colwidth = (sp->cols - 1) / cnt & ~(BOUND - 1); + colwidth = (sp->cols - 1) / cnt & ~(STANDARD_TAB - 1); if (colwidth >= 10) { - colwidth = (colwidth + BOUND) & ~(BOUND - 1); + colwidth = + (colwidth + STANDARD_TAB) & ~(STANDARD_TAB - 1); break; } colwidth = 0; } - /* - * Two passes. First, get the set of options to list, entering them - * into the column list or the overflow list. No error checking, - * since we know that at least one option (O_TERM) has the OPT_SET bit - * set. + /* + * Get the set of options to list, entering them into + * the column list or the overflow list. */ - for (b_num = s_num = 0, op = optlist; op->name; ++op) { + for (b_num = s_num = 0, op = optlist; op->name != NULL; ++op) { cnt = op - optlist; /* If OPT_NEVER set, it's never displayed. */ @@ -618,29 +651,32 @@ opts_dump(sp, type) b_op[b_num++] = cnt; } - numcols = (sp->cols - 1) / colwidth; - if (s_num > numcols) { - numrows = s_num / numcols; - if (s_num % numcols) - ++numrows; - } else - numrows = 1; - - for (row = 0; row < numrows;) { - for (base = row, col = 0; col < numcols; ++col) { - cnt = opts_print(sp, - &optlist[s_op[base]], &sp->opts[s_op[base]]); - if ((base += numrows) >= s_num) - break; - (void)ex_printf(EXCOOKIE, - "%*s", (int)(colwidth - cnt), ""); + if (s_num > 0) { + /* Figure out the number of columns. */ + numcols = (sp->cols - 1) / colwidth; + if (s_num > numcols) { + numrows = s_num / numcols; + if (s_num % numcols) + ++numrows; + } else + numrows = 1; + + /* Display the options in sorted order. */ + for (row = 0; row < numrows;) { + for (base = row, col = 0; col < numcols; ++col) { + cnt = opts_print(sp, &optlist[s_op[base]]); + if ((base += numrows) >= s_num) + break; + (void)ex_printf(EXCOOKIE, + "%*s", (int)(colwidth - cnt), ""); + } + if (++row < numrows || b_num) + (void)ex_printf(EXCOOKIE, "\n"); } - if (++row < numrows || b_num) - (void)ex_printf(EXCOOKIE, "\n"); } for (row = 0; row < b_num;) { - (void)opts_print(sp, &optlist[b_op[row]], &sp->opts[b_op[row]]); + (void)opts_print(sp, &optlist[b_op[row]]); if (++row < b_num) (void)ex_printf(EXCOOKIE, "\n"); } @@ -652,10 +688,9 @@ opts_dump(sp, type) * Print out an option. */ static int -opts_print(sp, op, spo) +opts_print(sp, op) SCR *sp; OPTLIST const *op; - OPTION *spo; { int curlen, offset; @@ -688,12 +723,11 @@ opts_save(sp, fp) SCR *sp; FILE *fp; { - OPTION *spo; OPTLIST const *op; int ch, cnt; char *p; - for (spo = sp->opts, op = optlist; op->name; ++op) { + for (op = optlist; op->name != NULL; ++op) { if (F_ISSET(op, OPT_NOSAVE)) continue; cnt = op - optlist; |