1996-11-01 06:45:43 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1991, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* Copyright (c) 1991, 1993, 1994, 1995, 1996
|
|
|
|
* Keith Bostic. All rights reserved.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for redistribution information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <bitstring.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-10-01 04:25:54 +00:00
|
|
|
#include <unctrl.h>
|
1996-11-01 06:45:43 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "../vi/vi.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
2015-04-10 13:26:05 +00:00
|
|
|
static int opts_abbcmp(const void *, const void *);
|
|
|
|
static int opts_cmp(const void *, const void *);
|
|
|
|
static int opts_print(SCR *, OPTLIST const *);
|
1996-11-01 06:45:43 +00:00
|
|
|
|
2013-08-11 09:44:58 +00:00
|
|
|
#ifdef USE_WIDECHAR
|
|
|
|
#define OPT_WC 0
|
|
|
|
#else
|
|
|
|
#define OPT_WC (OPT_NOSAVE | OPT_NDISP)
|
|
|
|
#endif
|
|
|
|
|
1996-11-01 06:45:43 +00:00
|
|
|
/*
|
|
|
|
* O'Reilly noted options and abbreviations are from "Learning the VI Editor",
|
|
|
|
* Fifth Edition, May 1992. There's no way of knowing what systems they are
|
|
|
|
* actually from.
|
|
|
|
*
|
|
|
|
* HPUX noted options and abbreviations are from "The Ultimate Guide to the
|
|
|
|
* VI and EX Text Editors", 1990.
|
|
|
|
*/
|
|
|
|
OPTLIST const optlist[] = {
|
|
|
|
/* O_ALTWERASE 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("altwerase"), f_altwerase, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_AUTOINDENT 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("autoindent"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_AUTOPRINT 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("autoprint"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_AUTOWRITE 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("autowrite"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_BACKUP 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("backup"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_BEAUTIFY 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("beautify"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_CDPATH 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("cdpath"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_CEDIT 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("cedit"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_COLUMNS 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("columns"), f_columns, OPT_NUM, OPT_NOSAVE},
|
|
|
|
/* O_COMBINED */
|
|
|
|
{L("combined"), NULL, OPT_0BOOL, OPT_NOSET|OPT_WC},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_COMMENT 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("comment"), NULL, OPT_0BOOL, 0},
|
|
|
|
/* O_TMPDIR 4BSD */
|
|
|
|
{L("directory"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_EDCOMPATIBLE 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("edcompatible"),NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_ERRORBELLS 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("errorbells"), NULL, OPT_0BOOL, 0},
|
|
|
|
/* O_ESCAPETIME 4.4BSD */
|
|
|
|
{L("escapetime"), NULL, OPT_NUM, 0},
|
2020-09-09 07:57:59 +00:00
|
|
|
/* O_EXPANDTAB NetBSD 5.0 */
|
|
|
|
{L("expandtab"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_EXRC System V (undocumented) */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("exrc"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_EXTENDED 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("extended"), f_recompile, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_FILEC 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("filec"), NULL, OPT_STR, 0},
|
|
|
|
/* O_FILEENCODING */
|
|
|
|
{L("fileencoding"),f_encoding, OPT_STR, OPT_WC},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_FLASH HPUX */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("flash"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_HARDTABS 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("hardtabs"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_ICLOWER 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("iclower"), f_recompile, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_IGNORECASE 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("ignorecase"), f_recompile, OPT_0BOOL, 0},
|
|
|
|
/* O_INPUTENCODING */
|
|
|
|
{L("inputencoding"),f_encoding, OPT_STR, OPT_WC},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_KEYTIME 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("keytime"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_LEFTRIGHT 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("leftright"), f_reformat, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_LINES 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("lines"), f_lines, OPT_NUM, OPT_NOSAVE},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_LISP 4BSD
|
|
|
|
* XXX
|
|
|
|
* When the lisp option is implemented, delete the OPT_NOSAVE flag,
|
|
|
|
* so that :mkexrc dumps it.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("lisp"), f_lisp, OPT_0BOOL, OPT_NOSAVE},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_LIST 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("list"), f_reformat, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_LOCKFILES 4.4BSD
|
|
|
|
* XXX
|
|
|
|
* Locking isn't reliable enough over NFS to require it, in addition,
|
|
|
|
* it's a serious startup performance problem over some remote links.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("lock"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_MAGIC 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("magic"), NULL, OPT_1BOOL, 0},
|
|
|
|
/* O_MATCHCHARS NetBSD 2.0 */
|
|
|
|
{L("matchchars"), NULL, OPT_STR, OPT_PAIRS},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_MATCHTIME 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("matchtime"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_MESG 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("mesg"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_MODELINE 4BSD
|
|
|
|
* !!!
|
|
|
|
* This has been documented in historical systems as both "modeline"
|
|
|
|
* and as "modelines". Regardless of the name, this option represents
|
|
|
|
* a security problem of mammoth proportions, not to mention a stunning
|
|
|
|
* example of what your intro CS professor referred to as the perils of
|
|
|
|
* mixing code and data. Don't add it, or I will kill you.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("modeline"), NULL, OPT_0BOOL, OPT_NOSET},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_MSGCAT 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("msgcat"), f_msgcat, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_NOPRINT 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("noprint"), f_print, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_NUMBER 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("number"), f_reformat, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_OCTAL 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("octal"), f_print, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_OPEN 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("open"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_OPTIMIZE 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("optimize"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_PARAGRAPHS 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("paragraphs"), NULL, OPT_STR, OPT_PAIRS},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_PATH 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("path"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_PRINT 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("print"), f_print, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_PROMPT 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("prompt"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_READONLY 4BSD (undocumented) */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("readonly"), f_readonly, OPT_0BOOL, OPT_ALWAYS},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_RECDIR 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("recdir"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_REDRAW 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("redraw"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_REMAP 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("remap"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_REPORT 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("report"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_RULER 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("ruler"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SCROLL 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("scroll"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SEARCHINCR 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("searchincr"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SECTIONS 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("sections"), NULL, OPT_STR, OPT_PAIRS},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SECURE 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("secure"), NULL, OPT_0BOOL, OPT_NOUNSET},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SHELL 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("shell"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SHELLMETA 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("shellmeta"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SHIFTWIDTH 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("shiftwidth"), NULL, OPT_NUM, OPT_NOZERO},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SHOWMATCH 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("showmatch"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SHOWMODE 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("showmode"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SIDESCROLL 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("sidescroll"), NULL, OPT_NUM, OPT_NOZERO},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SLOWOPEN 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("slowopen"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_SOURCEANY 4BSD (undocumented)
|
|
|
|
* !!!
|
|
|
|
* Historic vi, on startup, source'd $HOME/.exrc and ./.exrc, if they
|
|
|
|
* were owned by the user. The sourceany option was an undocumented
|
|
|
|
* feature of historic vi which permitted the startup source'ing of
|
|
|
|
* .exrc files the user didn't own. This is an obvious security problem,
|
|
|
|
* and we ignore the option.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("sourceany"), NULL, OPT_0BOOL, OPT_NOSET},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TABSTOP 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("tabstop"), f_reformat, OPT_NUM, OPT_NOZERO},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TAGLENGTH 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("taglength"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TAGS 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("tags"), NULL, OPT_STR, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TERM 4BSD
|
|
|
|
* !!!
|
|
|
|
* By default, the historic vi always displayed information about two
|
|
|
|
* options, redraw and term. Term seems sufficient.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("term"), NULL, OPT_STR, OPT_ADISP|OPT_NOSAVE},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TERSE 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("terse"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TILDEOP 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("tildeop"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TIMEOUT 4BSD (undocumented) */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("timeout"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_TTYWERASE 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("ttywerase"), f_ttywerase, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_VERBOSE 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("verbose"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_W1200 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("w1200"), f_w1200, OPT_NUM, OPT_NDISP|OPT_NOSAVE},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_W300 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("w300"), f_w300, OPT_NUM, OPT_NDISP|OPT_NOSAVE},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_W9600 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("w9600"), f_w9600, OPT_NUM, OPT_NDISP|OPT_NOSAVE},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_WARN 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("warn"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_WINDOW 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("window"), f_window, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_WINDOWNAME 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("windowname"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_WRAPLEN 4.4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("wraplen"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_WRAPMARGIN 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("wrapmargin"), NULL, OPT_NUM, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_WRAPSCAN 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("wrapscan"), NULL, OPT_1BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
/* O_WRITEANY 4BSD */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("writeany"), NULL, OPT_0BOOL, 0},
|
1996-11-01 06:45:43 +00:00
|
|
|
{NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct abbrev {
|
2015-04-10 13:26:05 +00:00
|
|
|
CHAR_T *name;
|
|
|
|
int offset;
|
1996-11-01 06:45:43 +00:00
|
|
|
} OABBREV;
|
|
|
|
|
|
|
|
static OABBREV const abbrev[] = {
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("ai"), O_AUTOINDENT}, /* 4BSD */
|
|
|
|
{L("ap"), O_AUTOPRINT}, /* 4BSD */
|
|
|
|
{L("aw"), O_AUTOWRITE}, /* 4BSD */
|
|
|
|
{L("bf"), O_BEAUTIFY}, /* 4BSD */
|
|
|
|
{L("co"), O_COLUMNS}, /* 4.4BSD */
|
|
|
|
{L("dir"), O_TMPDIR}, /* 4BSD */
|
|
|
|
{L("eb"), O_ERRORBELLS}, /* 4BSD */
|
|
|
|
{L("ed"), O_EDCOMPATIBLE}, /* 4BSD */
|
2020-09-09 07:57:59 +00:00
|
|
|
{L("et"), O_EXPANDTAB}, /* NetBSD 5.0 */
|
2013-08-11 09:44:58 +00:00
|
|
|
{L("ex"), O_EXRC}, /* System V (undocumented) */
|
|
|
|
{L("fe"), O_FILEENCODING},
|
|
|
|
{L("ht"), O_HARDTABS}, /* 4BSD */
|
|
|
|
{L("ic"), O_IGNORECASE}, /* 4BSD */
|
|
|
|
{L("ie"), O_INPUTENCODING},
|
|
|
|
{L("li"), O_LINES}, /* 4.4BSD */
|
|
|
|
{L("modelines"), O_MODELINE}, /* HPUX */
|
|
|
|
{L("nu"), O_NUMBER}, /* 4BSD */
|
|
|
|
{L("opt"), O_OPTIMIZE}, /* 4BSD */
|
|
|
|
{L("para"), O_PARAGRAPHS}, /* 4BSD */
|
|
|
|
{L("re"), O_REDRAW}, /* O'Reilly */
|
|
|
|
{L("ro"), O_READONLY}, /* 4BSD (undocumented) */
|
|
|
|
{L("scr"), O_SCROLL}, /* 4BSD (undocumented) */
|
|
|
|
{L("sect"), O_SECTIONS}, /* O'Reilly */
|
|
|
|
{L("sh"), O_SHELL}, /* 4BSD */
|
|
|
|
{L("slow"), O_SLOWOPEN}, /* 4BSD */
|
|
|
|
{L("sm"), O_SHOWMATCH}, /* 4BSD */
|
|
|
|
{L("smd"), O_SHOWMODE}, /* 4BSD */
|
|
|
|
{L("sw"), O_SHIFTWIDTH}, /* 4BSD */
|
|
|
|
{L("tag"), O_TAGS}, /* 4BSD (undocumented) */
|
|
|
|
{L("tl"), O_TAGLENGTH}, /* 4BSD */
|
|
|
|
{L("to"), O_TIMEOUT}, /* 4BSD (undocumented) */
|
|
|
|
{L("ts"), O_TABSTOP}, /* 4BSD */
|
|
|
|
{L("tty"), O_TERM}, /* 4BSD (undocumented) */
|
|
|
|
{L("ttytype"), O_TERM}, /* 4BSD (undocumented) */
|
|
|
|
{L("w"), O_WINDOW}, /* O'Reilly */
|
|
|
|
{L("wa"), O_WRITEANY}, /* 4BSD */
|
|
|
|
{L("wi"), O_WINDOW}, /* 4BSD (undocumented) */
|
|
|
|
{L("wl"), O_WRAPLEN}, /* 4.4BSD */
|
|
|
|
{L("wm"), O_WRAPMARGIN}, /* 4BSD */
|
|
|
|
{L("ws"), O_WRAPSCAN}, /* 4BSD */
|
1996-11-01 06:45:43 +00:00
|
|
|
{NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_init --
|
|
|
|
* Initialize some of the options.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: int opts_init(SCR *, int *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_init(SCR *sp, int *oargs)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
ARGS *argv[2], a, b;
|
|
|
|
OPTLIST const *op;
|
|
|
|
u_long v;
|
2013-08-11 09:44:58 +00:00
|
|
|
int cnt, optindx = 0;
|
|
|
|
char *s;
|
|
|
|
CHAR_T b2[1024];
|
1996-11-01 06:45:43 +00:00
|
|
|
|
2013-08-11 09:44:58 +00:00
|
|
|
a.bp = b2;
|
1996-11-01 06:45:43 +00:00
|
|
|
b.bp = NULL;
|
|
|
|
a.len = b.len = 0;
|
|
|
|
argv[0] = &a;
|
|
|
|
argv[1] = &b;
|
|
|
|
|
|
|
|
/* Set numeric and string default values. */
|
2020-10-01 04:25:54 +00:00
|
|
|
#define OI(indx, str) do { \
|
2013-08-11 09:44:58 +00:00
|
|
|
a.len = STRLEN(str); \
|
|
|
|
if ((CHAR_T*)str != b2) /* GCC puts strings in text-space. */ \
|
|
|
|
(void)MEMCPY(b2, str, a.len+1); \
|
1996-11-01 06:45:43 +00:00
|
|
|
if (opts_set(sp, argv, NULL)) { \
|
|
|
|
optindx = indx; \
|
|
|
|
goto err; \
|
|
|
|
} \
|
2020-10-01 04:25:54 +00:00
|
|
|
} while (0)
|
1996-11-01 06:45:43 +00:00
|
|
|
/*
|
|
|
|
* Indirect global options to global space. Specifically, set up
|
|
|
|
* terminal, lines, columns first, they're used by other options.
|
|
|
|
* Note, don't set the flags until we've set up the indirection.
|
|
|
|
*/
|
|
|
|
if (o_set(sp, O_TERM, 0, NULL, GO_TERM))
|
|
|
|
goto err;
|
|
|
|
F_SET(&sp->opts[O_TERM], OPT_GLOBAL);
|
|
|
|
if (o_set(sp, O_LINES, 0, NULL, GO_LINES))
|
|
|
|
goto err;
|
|
|
|
F_SET(&sp->opts[O_LINES], OPT_GLOBAL);
|
|
|
|
if (o_set(sp, O_COLUMNS, 0, NULL, GO_COLUMNS))
|
|
|
|
goto err;
|
|
|
|
F_SET(&sp->opts[O_COLUMNS], OPT_GLOBAL);
|
|
|
|
if (o_set(sp, O_SECURE, 0, NULL, GO_SECURE))
|
|
|
|
goto err;
|
|
|
|
F_SET(&sp->opts[O_SECURE], OPT_GLOBAL);
|
|
|
|
|
|
|
|
/* Initialize string values. */
|
2013-08-11 09:44:58 +00:00
|
|
|
(void)SPRINTF(b2, SIZE(b2),
|
|
|
|
L("cdpath=%s"), (s = getenv("CDPATH")) == NULL ? ":" : s);
|
|
|
|
OI(O_CDPATH, b2);
|
|
|
|
OI(O_CEDIT, L("cedit=\033"));
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* !!!
|
|
|
|
* Vi historically stored temporary files in /var/tmp. We store them
|
|
|
|
* in /tmp by default, hoping it's a memory based file system. There
|
|
|
|
* are two ways to change this -- the user can set either the directory
|
|
|
|
* option or the TMPDIR environmental variable.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
(void)SPRINTF(b2, SIZE(b2),
|
|
|
|
L("directory=%s"), (s = getenv("TMPDIR")) == NULL ? _PATH_TMP : s);
|
|
|
|
OI(O_TMPDIR, b2);
|
|
|
|
OI(O_ESCAPETIME, L("escapetime=6"));
|
|
|
|
OI(O_FILEC, L("filec=\t"));
|
|
|
|
OI(O_KEYTIME, L("keytime=6"));
|
|
|
|
OI(O_MATCHCHARS, L("matchchars=()[]{}"));
|
|
|
|
OI(O_MATCHTIME, L("matchtime=7"));
|
|
|
|
(void)SPRINTF(b2, SIZE(b2), L("msgcat=%s"), _PATH_MSGCAT);
|
|
|
|
OI(O_MSGCAT, b2);
|
|
|
|
OI(O_REPORT, L("report=5"));
|
|
|
|
OI(O_PARAGRAPHS, L("paragraphs=IPLPPPQPP LIpplpipbp"));
|
|
|
|
(void)SPRINTF(b2, SIZE(b2), L("path=%s"), "");
|
|
|
|
OI(O_PATH, b2);
|
2020-10-01 04:25:54 +00:00
|
|
|
(void)SPRINTF(b2, SIZE(b2), L("recdir=%s"), NVI_PATH_PRESERVE);
|
2013-08-11 09:44:58 +00:00
|
|
|
OI(O_RECDIR, b2);
|
|
|
|
OI(O_SECTIONS, L("sections=NHSHH HUnhsh"));
|
|
|
|
(void)SPRINTF(b2, SIZE(b2),
|
|
|
|
L("shell=%s"), (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s);
|
|
|
|
OI(O_SHELL, b2);
|
|
|
|
OI(O_SHELLMETA, L("shellmeta=~{[*?$`'\"\\"));
|
|
|
|
OI(O_SHIFTWIDTH, L("shiftwidth=8"));
|
|
|
|
OI(O_SIDESCROLL, L("sidescroll=16"));
|
|
|
|
OI(O_TABSTOP, L("tabstop=8"));
|
|
|
|
(void)SPRINTF(b2, SIZE(b2), L("tags=%s"), _PATH_TAGS);
|
|
|
|
OI(O_TAGS, b2);
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Initialize O_SCROLL here, after term; initializing term should
|
|
|
|
* have created a LINES/COLUMNS value.
|
|
|
|
*/
|
|
|
|
if ((v = (O_VAL(sp, O_LINES) - 1) / 2) == 0)
|
|
|
|
v = 1;
|
2013-08-11 09:44:58 +00:00
|
|
|
(void)SPRINTF(b2, SIZE(b2), L("scroll=%ld"), v);
|
|
|
|
OI(O_SCROLL, b2);
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The default window option values are:
|
|
|
|
* 8 if baud rate <= 600
|
|
|
|
* 16 if baud rate <= 1200
|
|
|
|
* LINES - 1 if baud rate > 1200
|
|
|
|
*
|
|
|
|
* Note, the windows option code will correct any too-large value
|
|
|
|
* or when the O_LINES value is 1.
|
|
|
|
*/
|
|
|
|
if (sp->gp->scr_baud(sp, &v))
|
|
|
|
return (1);
|
|
|
|
if (v <= 600)
|
|
|
|
v = 8;
|
|
|
|
else if (v <= 1200)
|
|
|
|
v = 16;
|
2013-08-11 09:44:58 +00:00
|
|
|
else if ((v = O_VAL(sp, O_LINES) - 1) == 0)
|
|
|
|
v = 1;
|
|
|
|
|
|
|
|
(void)SPRINTF(b2, SIZE(b2), L("window=%lu"), v);
|
|
|
|
OI(O_WINDOW, b2);
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set boolean default values, and copy all settings into the default
|
|
|
|
* information. OS_NOFREE is set, we're copying, not replacing.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt) {
|
|
|
|
if (F_ISSET(op, OPT_GLOBAL))
|
|
|
|
continue;
|
1996-11-01 06:45:43 +00:00
|
|
|
switch (op->type) {
|
|
|
|
case OPT_0BOOL:
|
|
|
|
break;
|
|
|
|
case OPT_1BOOL:
|
|
|
|
O_SET(sp, cnt);
|
|
|
|
O_D_SET(sp, cnt);
|
|
|
|
break;
|
|
|
|
case OPT_NUM:
|
|
|
|
o_set(sp, cnt, OS_DEF, NULL, O_VAL(sp, cnt));
|
|
|
|
break;
|
|
|
|
case OPT_STR:
|
|
|
|
if (O_STR(sp, cnt) != NULL && o_set(sp, cnt,
|
|
|
|
OS_DEF | OS_NOFREE | OS_STRDUP, O_STR(sp, cnt), 0))
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2013-08-11 09:44:58 +00:00
|
|
|
}
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* !!!
|
|
|
|
* Some options can be initialized by the command name or the
|
|
|
|
* command-line arguments. They don't set the default values,
|
|
|
|
* it's historic practice.
|
|
|
|
*/
|
|
|
|
for (; *oargs != -1; ++oargs)
|
|
|
|
OI(*oargs, optlist[*oargs].name);
|
|
|
|
#undef OI
|
2013-08-11 09:44:58 +00:00
|
|
|
return (0);
|
1996-11-01 06:45:43 +00:00
|
|
|
|
2013-08-11 09:44:58 +00:00
|
|
|
err: msgq_wstr(sp, M_ERR, optlist[optindx].name,
|
|
|
|
"031|Unable to set default %s option");
|
1996-11-01 06:45:43 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_set --
|
|
|
|
* Change the values of one or more options.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: int opts_set(SCR *, ARGS *[], char *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_set(SCR *sp, ARGS *argv[], char *usage)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
enum optdisp disp;
|
|
|
|
enum nresult nret;
|
|
|
|
OPTLIST const *op;
|
|
|
|
OPTION *spo;
|
2013-08-11 09:44:58 +00:00
|
|
|
u_long isset, turnoff, value;
|
1996-11-01 06:45:43 +00:00
|
|
|
int ch, equals, nf, nf2, offset, qmark, rval;
|
2013-08-11 09:44:58 +00:00
|
|
|
CHAR_T *endp, *name, *p, *sep;
|
|
|
|
char *p2, *t2;
|
|
|
|
char *np;
|
|
|
|
size_t nlen;
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
disp = NO_DISPLAY;
|
|
|
|
for (rval = 0; argv[0]->len != 0; ++argv) {
|
|
|
|
/*
|
|
|
|
* The historic vi dumped the options for each occurrence of
|
|
|
|
* "all" in the set list. Puhleeze.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
if (!STRCMP(argv[0]->bp, L("all"))) {
|
1996-11-01 06:45:43 +00:00
|
|
|
disp = ALL_DISPLAY;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find equals sign or question mark. */
|
|
|
|
for (sep = NULL, equals = qmark = 0,
|
|
|
|
p = name = argv[0]->bp; (ch = *p) != '\0'; ++p)
|
|
|
|
if (ch == '=' || ch == '?') {
|
|
|
|
if (p == name) {
|
|
|
|
if (usage != NULL)
|
|
|
|
msgq(sp, M_ERR,
|
|
|
|
"032|Usage: %s", usage);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
sep = p;
|
|
|
|
if (ch == '=')
|
|
|
|
equals = 1;
|
|
|
|
else
|
|
|
|
qmark = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
turnoff = 0;
|
|
|
|
op = NULL;
|
|
|
|
if (sep != NULL)
|
|
|
|
*sep++ = '\0';
|
|
|
|
|
|
|
|
/* Search for the name, then name without any leading "no". */
|
|
|
|
if ((op = opts_search(name)) == NULL &&
|
|
|
|
name[0] == 'n' && name[1] == 'o') {
|
|
|
|
turnoff = 1;
|
|
|
|
name += 2;
|
|
|
|
op = opts_search(name);
|
|
|
|
}
|
|
|
|
if (op == NULL) {
|
|
|
|
opts_nomatch(sp, name);
|
|
|
|
rval = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find current option values. */
|
|
|
|
offset = op - optlist;
|
|
|
|
spo = sp->opts + offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* !!!
|
|
|
|
* Historically, the question mark could be a separate
|
|
|
|
* argument.
|
|
|
|
*/
|
|
|
|
if (!equals && !qmark &&
|
|
|
|
argv[1]->len == 1 && argv[1]->bp[0] == '?') {
|
|
|
|
++argv;
|
|
|
|
qmark = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set name, value. */
|
|
|
|
switch (op->type) {
|
|
|
|
case OPT_0BOOL:
|
|
|
|
case OPT_1BOOL:
|
|
|
|
/* Some options may not be reset. */
|
|
|
|
if (F_ISSET(op, OPT_NOUNSET) && turnoff) {
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"291|set: the %s option may not be turned off");
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some options may not be set. */
|
|
|
|
if (F_ISSET(op, OPT_NOSET) && !turnoff) {
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"313|set: the %s option may never be turned on");
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (equals) {
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"034|set: [no]%s option doesn't take a value");
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (qmark) {
|
|
|
|
if (!disp)
|
|
|
|
disp = SELECT_DISPLAY;
|
|
|
|
F_SET(spo, OPT_SELECTED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do nothing if the value is unchanged, the underlying
|
|
|
|
* functions can be expensive.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
isset = !turnoff;
|
2020-10-01 04:25:54 +00:00
|
|
|
if (!F_ISSET(op, OPT_ALWAYS)) {
|
2013-08-11 09:44:58 +00:00
|
|
|
if (isset) {
|
1996-11-01 06:45:43 +00:00
|
|
|
if (O_ISSET(sp, offset))
|
|
|
|
break;
|
2013-08-11 09:44:58 +00:00
|
|
|
} else
|
|
|
|
if (!O_ISSET(sp, offset))
|
|
|
|
break;
|
2020-10-01 04:25:54 +00:00
|
|
|
}
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
/* Report to subsystems. */
|
2013-08-11 09:44:58 +00:00
|
|
|
if ((op->func != NULL &&
|
|
|
|
op->func(sp, spo, NULL, &isset)) ||
|
|
|
|
ex_optchange(sp, offset, NULL, &isset) ||
|
|
|
|
v_optchange(sp, offset, NULL, &isset) ||
|
|
|
|
sp->gp->scr_optchange(sp, offset, NULL, &isset)) {
|
1996-11-01 06:45:43 +00:00
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the value. */
|
2013-08-11 09:44:58 +00:00
|
|
|
if (isset)
|
1996-11-01 06:45:43 +00:00
|
|
|
O_SET(sp, offset);
|
2013-08-11 09:44:58 +00:00
|
|
|
else
|
|
|
|
O_CLR(sp, offset);
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
case OPT_NUM:
|
|
|
|
if (turnoff) {
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"035|set: %s option isn't a boolean");
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (qmark || !equals) {
|
|
|
|
if (!disp)
|
|
|
|
disp = SELECT_DISPLAY;
|
|
|
|
F_SET(spo, OPT_SELECTED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-11 09:44:58 +00:00
|
|
|
if (!ISDIGIT(sep[0]))
|
1996-11-01 06:45:43 +00:00
|
|
|
goto badnum;
|
|
|
|
if ((nret =
|
|
|
|
nget_uslong(&value, sep, &endp, 10)) != NUM_OK) {
|
2013-08-11 09:44:58 +00:00
|
|
|
INT2CHAR(sp, name, STRLEN(name) + 1,
|
|
|
|
np, nlen);
|
|
|
|
p2 = msg_print(sp, np, &nf);
|
|
|
|
INT2CHAR(sp, sep, STRLEN(sep) + 1,
|
|
|
|
np, nlen);
|
|
|
|
t2 = msg_print(sp, np, &nf2);
|
1996-11-01 06:45:43 +00:00
|
|
|
switch (nret) {
|
|
|
|
case NUM_ERR:
|
|
|
|
msgq(sp, M_SYSERR,
|
2013-08-11 09:44:58 +00:00
|
|
|
"036|set: %s option: %s", p2, t2);
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
case NUM_OVER:
|
|
|
|
msgq(sp, M_ERR,
|
2013-08-11 09:44:58 +00:00
|
|
|
"037|set: %s option: %s: value overflow", p2, t2);
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
case NUM_OK:
|
|
|
|
case NUM_UNDER:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (nf)
|
2013-08-11 09:44:58 +00:00
|
|
|
FREE_SPACE(sp, p2, 0);
|
1996-11-01 06:45:43 +00:00
|
|
|
if (nf2)
|
2013-08-11 09:44:58 +00:00
|
|
|
FREE_SPACE(sp, t2, 0);
|
1996-11-01 06:45:43 +00:00
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-11 09:44:58 +00:00
|
|
|
if (*endp && !cmdskip(*endp)) {
|
|
|
|
badnum: INT2CHAR(sp, name, STRLEN(name) + 1,
|
|
|
|
np, nlen);
|
|
|
|
p2 = msg_print(sp, np, &nf);
|
|
|
|
INT2CHAR(sp, sep, STRLEN(sep) + 1,
|
|
|
|
np, nlen);
|
|
|
|
t2 = msg_print(sp, np, &nf2);
|
1996-11-01 06:45:43 +00:00
|
|
|
msgq(sp, M_ERR,
|
2013-08-11 09:44:58 +00:00
|
|
|
"038|set: %s option: %s is an illegal number", p2, t2);
|
1996-11-01 06:45:43 +00:00
|
|
|
if (nf)
|
2013-08-11 09:44:58 +00:00
|
|
|
FREE_SPACE(sp, p2, 0);
|
1996-11-01 06:45:43 +00:00
|
|
|
if (nf2)
|
2013-08-11 09:44:58 +00:00
|
|
|
FREE_SPACE(sp, t2, 0);
|
1996-11-01 06:45:43 +00:00
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some options may never be set to zero. */
|
|
|
|
if (F_ISSET(op, OPT_NOZERO) && value == 0) {
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"314|set: the %s option may never be set to 0");
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do nothing if the value is unchanged, the underlying
|
|
|
|
* functions can be expensive.
|
|
|
|
*/
|
|
|
|
if (!F_ISSET(op, OPT_ALWAYS) &&
|
|
|
|
O_VAL(sp, offset) == value)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Report to subsystems. */
|
2013-08-11 09:44:58 +00:00
|
|
|
INT2CHAR(sp, sep, STRLEN(sep) + 1, np, nlen);
|
|
|
|
if ((op->func != NULL &&
|
|
|
|
op->func(sp, spo, np, &value)) ||
|
|
|
|
ex_optchange(sp, offset, np, &value) ||
|
|
|
|
v_optchange(sp, offset, np, &value) ||
|
|
|
|
sp->gp->scr_optchange(sp, offset, np, &value)) {
|
1996-11-01 06:45:43 +00:00
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the value. */
|
|
|
|
if (o_set(sp, offset, 0, NULL, value))
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
case OPT_STR:
|
|
|
|
if (turnoff) {
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"039|set: %s option isn't a boolean");
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (qmark || !equals) {
|
|
|
|
if (!disp)
|
|
|
|
disp = SELECT_DISPLAY;
|
|
|
|
F_SET(spo, OPT_SELECTED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-11 09:44:58 +00:00
|
|
|
/* Check for strings that must have even length. */
|
|
|
|
if (F_ISSET(op, OPT_PAIRS) && STRLEN(sep) & 1) {
|
|
|
|
msgq_wstr(sp, M_ERR, name,
|
|
|
|
"047|The %s option must be in two character groups");
|
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1996-11-01 06:45:43 +00:00
|
|
|
/*
|
|
|
|
* Do nothing if the value is unchanged, the underlying
|
|
|
|
* functions can be expensive.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
INT2CHAR(sp, sep, STRLEN(sep) + 1, np, nlen);
|
1996-11-01 06:45:43 +00:00
|
|
|
if (!F_ISSET(op, OPT_ALWAYS) &&
|
|
|
|
O_STR(sp, offset) != NULL &&
|
2013-08-11 09:44:58 +00:00
|
|
|
!strcmp(O_STR(sp, offset), np))
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Report to subsystems. */
|
2013-08-11 09:44:58 +00:00
|
|
|
if ((op->func != NULL &&
|
|
|
|
op->func(sp, spo, np, NULL)) ||
|
|
|
|
ex_optchange(sp, offset, np, NULL) ||
|
|
|
|
v_optchange(sp, offset, np, NULL) ||
|
|
|
|
sp->gp->scr_optchange(sp, offset, np, NULL)) {
|
1996-11-01 06:45:43 +00:00
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the value. */
|
2013-08-11 09:44:58 +00:00
|
|
|
if (o_set(sp, offset, OS_STRDUP, np, 0))
|
1996-11-01 06:45:43 +00:00
|
|
|
rval = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (disp != NO_DISPLAY)
|
|
|
|
opts_dump(sp, disp);
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* o_set --
|
|
|
|
* Set an option's value.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: int o_set(SCR *, int, u_int, char *, u_long);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2020-09-09 07:57:59 +00:00
|
|
|
o_set(SCR *sp, int opt, u_int flags, char *str, u_long val)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
OPTION *op;
|
|
|
|
|
|
|
|
/* Set a pointer to the options area. */
|
|
|
|
op = F_ISSET(&sp->opts[opt], OPT_GLOBAL) ?
|
|
|
|
&sp->gp->opts[sp->opts[opt].o_cur.val] : &sp->opts[opt];
|
|
|
|
|
|
|
|
/* Copy the string, if requested. */
|
|
|
|
if (LF_ISSET(OS_STRDUP) && (str = strdup(str)) == NULL) {
|
|
|
|
msgq(sp, M_SYSERR, NULL);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free the previous string, if requested, and set the value. */
|
|
|
|
if LF_ISSET(OS_DEF)
|
|
|
|
if (LF_ISSET(OS_STR | OS_STRDUP)) {
|
2020-09-09 07:57:59 +00:00
|
|
|
if (!LF_ISSET(OS_NOFREE))
|
1996-11-01 06:45:43 +00:00
|
|
|
free(op->o_def.str);
|
|
|
|
op->o_def.str = str;
|
|
|
|
} else
|
|
|
|
op->o_def.val = val;
|
|
|
|
else
|
|
|
|
if (LF_ISSET(OS_STR | OS_STRDUP)) {
|
2020-09-09 07:57:59 +00:00
|
|
|
if (!LF_ISSET(OS_NOFREE))
|
1996-11-01 06:45:43 +00:00
|
|
|
free(op->o_cur.str);
|
|
|
|
op->o_cur.str = str;
|
|
|
|
} else
|
|
|
|
op->o_cur.val = val;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_empty --
|
|
|
|
* Return 1 if the string option is invalid, 0 if it's OK.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: int opts_empty(SCR *, int, int);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_empty(SCR *sp, int off, int silent)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = O_STR(sp, off)) == NULL || p[0] == '\0') {
|
|
|
|
if (!silent)
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, optlist[off].name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"305|No %s edit option specified");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_dump --
|
|
|
|
* List the current values of selected options.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: void opts_dump(SCR *, enum optdisp);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_dump(SCR *sp, enum optdisp type)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
OPTLIST const *op;
|
|
|
|
int base, b_num, cnt, col, colwidth, curlen, s_num;
|
|
|
|
int numcols, numrows, row;
|
|
|
|
int b_op[O_OPTIONCOUNT], s_op[O_OPTIONCOUNT];
|
|
|
|
char nbuf[20];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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, testing from 10 columns to 1.
|
|
|
|
*/
|
|
|
|
for (numcols = 10; numcols > 1; --numcols) {
|
|
|
|
colwidth = sp->cols / numcols & ~(STANDARD_TAB - 1);
|
|
|
|
if (colwidth >= 10) {
|
|
|
|
colwidth =
|
|
|
|
(colwidth + STANDARD_TAB) & ~(STANDARD_TAB - 1);
|
|
|
|
numcols = sp->cols / colwidth;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
colwidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 != NULL; ++op) {
|
|
|
|
cnt = op - optlist;
|
|
|
|
|
|
|
|
/* If OPT_NDISP set, it's never displayed. */
|
|
|
|
if (F_ISSET(op, OPT_NDISP))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ALL_DISPLAY: /* Display all. */
|
|
|
|
break;
|
|
|
|
case CHANGED_DISPLAY: /* Display changed. */
|
|
|
|
/* If OPT_ADISP set, it's always "changed". */
|
|
|
|
if (F_ISSET(op, OPT_ADISP))
|
|
|
|
break;
|
|
|
|
switch (op->type) {
|
|
|
|
case OPT_0BOOL:
|
|
|
|
case OPT_1BOOL:
|
|
|
|
case OPT_NUM:
|
|
|
|
if (O_VAL(sp, cnt) == O_D_VAL(sp, cnt))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case OPT_STR:
|
|
|
|
if (O_STR(sp, cnt) == O_D_STR(sp, cnt) ||
|
2013-08-11 09:44:58 +00:00
|
|
|
(O_D_STR(sp, cnt) != NULL &&
|
|
|
|
!strcmp(O_STR(sp, cnt), O_D_STR(sp, cnt))))
|
1996-11-01 06:45:43 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SELECT_DISPLAY: /* Display selected. */
|
|
|
|
if (!F_ISSET(&sp->opts[cnt], OPT_SELECTED))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case NO_DISPLAY:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
F_CLR(&sp->opts[cnt], OPT_SELECTED);
|
|
|
|
|
2013-08-11 09:44:58 +00:00
|
|
|
curlen = STRLEN(op->name);
|
1996-11-01 06:45:43 +00:00
|
|
|
switch (op->type) {
|
|
|
|
case OPT_0BOOL:
|
|
|
|
case OPT_1BOOL:
|
|
|
|
if (!O_ISSET(sp, cnt))
|
|
|
|
curlen += 2;
|
|
|
|
break;
|
|
|
|
case OPT_NUM:
|
|
|
|
(void)snprintf(nbuf,
|
|
|
|
sizeof(nbuf), "%ld", O_VAL(sp, cnt));
|
|
|
|
curlen += strlen(nbuf);
|
|
|
|
break;
|
|
|
|
case OPT_STR:
|
|
|
|
if (O_STR(sp, cnt) != NULL)
|
|
|
|
curlen += strlen(O_STR(sp, cnt));
|
|
|
|
curlen += 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Offset by 2 so there's a gap. */
|
|
|
|
if (curlen <= colwidth - 2)
|
|
|
|
s_op[s_num++] = cnt;
|
|
|
|
else
|
|
|
|
b_op[b_num++] = cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s_num > 0) {
|
|
|
|
/* Figure out the number of rows. */
|
|
|
|
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(sp, "%*s",
|
|
|
|
(int)(colwidth - cnt), "");
|
|
|
|
}
|
|
|
|
if (++row < numrows || b_num)
|
|
|
|
(void)ex_puts(sp, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (row = 0; row < b_num;) {
|
|
|
|
(void)opts_print(sp, &optlist[b_op[row]]);
|
|
|
|
if (++row < b_num)
|
|
|
|
(void)ex_puts(sp, "\n");
|
|
|
|
}
|
|
|
|
(void)ex_puts(sp, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_print --
|
|
|
|
* Print out an option.
|
|
|
|
*/
|
|
|
|
static int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_print(SCR *sp, OPTLIST const *op)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
int curlen, offset;
|
2020-10-01 04:25:54 +00:00
|
|
|
const char *p;
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
curlen = 0;
|
|
|
|
offset = op - optlist;
|
|
|
|
switch (op->type) {
|
|
|
|
case OPT_0BOOL:
|
|
|
|
case OPT_1BOOL:
|
|
|
|
curlen += ex_printf(sp,
|
2013-08-11 09:44:58 +00:00
|
|
|
"%s"WS, O_ISSET(sp, offset) ? "" : "no", op->name);
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
case OPT_NUM:
|
2013-08-11 09:44:58 +00:00
|
|
|
curlen += ex_printf(sp, WS"=%ld", op->name, O_VAL(sp, offset));
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
case OPT_STR:
|
2020-10-01 04:25:54 +00:00
|
|
|
curlen += ex_printf(sp, WS"=\"", op->name);
|
|
|
|
p = O_STR(sp, offset);
|
|
|
|
/* Keep correct count for unprintable character sequences */
|
|
|
|
if (p != NULL)
|
|
|
|
for (; *p != '\0'; ++p)
|
|
|
|
curlen += ex_puts(sp, unctrl(*p));
|
|
|
|
curlen += ex_puts(sp, "\"");
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (curlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_save --
|
|
|
|
* Write the current configuration to a file.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: int opts_save(SCR *, FILE *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_save(SCR *sp, FILE *fp)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
OPTLIST const *op;
|
2013-08-11 09:44:58 +00:00
|
|
|
CHAR_T ch, *p;
|
|
|
|
char nch, *np;
|
|
|
|
int cnt;
|
1996-11-01 06:45:43 +00:00
|
|
|
|
|
|
|
for (op = optlist; op->name != NULL; ++op) {
|
|
|
|
if (F_ISSET(op, OPT_NOSAVE))
|
|
|
|
continue;
|
|
|
|
cnt = op - optlist;
|
|
|
|
switch (op->type) {
|
|
|
|
case OPT_0BOOL:
|
|
|
|
case OPT_1BOOL:
|
|
|
|
if (O_ISSET(sp, cnt))
|
2013-08-11 09:44:58 +00:00
|
|
|
(void)fprintf(fp, "set "WS"\n", op->name);
|
1996-11-01 06:45:43 +00:00
|
|
|
else
|
2013-08-11 09:44:58 +00:00
|
|
|
(void)fprintf(fp, "set no"WS"\n", op->name);
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
case OPT_NUM:
|
|
|
|
(void)fprintf(fp,
|
2013-08-11 09:44:58 +00:00
|
|
|
"set "WS"=%-3ld\n", op->name, O_VAL(sp, cnt));
|
1996-11-01 06:45:43 +00:00
|
|
|
break;
|
|
|
|
case OPT_STR:
|
|
|
|
if (O_STR(sp, cnt) == NULL)
|
|
|
|
break;
|
|
|
|
(void)fprintf(fp, "set ");
|
|
|
|
for (p = op->name; (ch = *p) != '\0'; ++p) {
|
2013-08-11 09:44:58 +00:00
|
|
|
if (cmdskip(ch) || ch == '\\')
|
1996-11-01 06:45:43 +00:00
|
|
|
(void)putc('\\', fp);
|
2013-08-11 09:44:58 +00:00
|
|
|
fprintf(fp, WC, ch);
|
1996-11-01 06:45:43 +00:00
|
|
|
}
|
|
|
|
(void)putc('=', fp);
|
2013-08-11 09:44:58 +00:00
|
|
|
for (np = O_STR(sp, cnt); (nch = *np) != '\0'; ++np) {
|
|
|
|
if (cmdskip(nch) || nch == '\\')
|
1996-11-01 06:45:43 +00:00
|
|
|
(void)putc('\\', fp);
|
2013-08-11 09:44:58 +00:00
|
|
|
(void)putc(nch, fp);
|
1996-11-01 06:45:43 +00:00
|
|
|
}
|
|
|
|
(void)putc('\n', fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ferror(fp)) {
|
|
|
|
msgq(sp, M_SYSERR, NULL);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_search --
|
|
|
|
* Search for an option.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: OPTLIST const *opts_search(CHAR_T *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
OPTLIST const *
|
2013-08-11 09:44:58 +00:00
|
|
|
opts_search(CHAR_T *name)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
OPTLIST const *op, *found;
|
|
|
|
OABBREV atmp, *ap;
|
|
|
|
OPTLIST otmp;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/* Check list of abbreviations. */
|
|
|
|
atmp.name = name;
|
|
|
|
if ((ap = bsearch(&atmp, abbrev, sizeof(abbrev) / sizeof(OABBREV) - 1,
|
|
|
|
sizeof(OABBREV), opts_abbcmp)) != NULL)
|
|
|
|
return (optlist + ap->offset);
|
|
|
|
|
|
|
|
/* Check list of options. */
|
|
|
|
otmp.name = name;
|
|
|
|
if ((op = bsearch(&otmp, optlist, sizeof(optlist) / sizeof(OPTLIST) - 1,
|
|
|
|
sizeof(OPTLIST), opts_cmp)) != NULL)
|
|
|
|
return (op);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if the name is the prefix of one (and only one)
|
|
|
|
* option. If so, return the option.
|
|
|
|
*/
|
2013-08-11 09:44:58 +00:00
|
|
|
len = STRLEN(name);
|
1996-11-01 06:45:43 +00:00
|
|
|
for (found = NULL, op = optlist; op->name != NULL; ++op) {
|
|
|
|
if (op->name[0] < name[0])
|
|
|
|
continue;
|
|
|
|
if (op->name[0] > name[0])
|
|
|
|
break;
|
2013-08-11 09:44:58 +00:00
|
|
|
if (!MEMCMP(op->name, name, len)) {
|
1996-11-01 06:45:43 +00:00
|
|
|
if (found != NULL)
|
|
|
|
return (NULL);
|
|
|
|
found = op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (found);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_nomatch --
|
|
|
|
* Standard nomatch error message for options.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: void opts_nomatch(SCR *, CHAR_T *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_nomatch(SCR *sp, CHAR_T *name)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
2013-08-11 09:44:58 +00:00
|
|
|
msgq_wstr(sp, M_ERR, name,
|
1996-11-01 06:45:43 +00:00
|
|
|
"033|set: no %s option: 'set all' gives all option values");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_abbcmp(const void *a, const void *b)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
2015-04-10 13:26:05 +00:00
|
|
|
return(STRCMP(((OABBREV *)a)->name, ((OABBREV *)b)->name));
|
1996-11-01 06:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_cmp(const void *a, const void *b)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
2015-04-10 13:26:05 +00:00
|
|
|
return(STRCMP(((OPTLIST *)a)->name, ((OPTLIST *)b)->name));
|
1996-11-01 06:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_copy --
|
|
|
|
* Copy a screen's OPTION array.
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: int opts_copy(SCR *, SCR *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2020-09-09 07:57:59 +00:00
|
|
|
opts_copy(SCR *orig, SCR *sp)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
int cnt, rval;
|
|
|
|
|
|
|
|
/* Copy most everything without change. */
|
|
|
|
memcpy(sp->opts, orig->opts, sizeof(orig->opts));
|
|
|
|
|
|
|
|
/* Copy the string edit options. */
|
|
|
|
for (cnt = rval = 0; cnt < O_OPTIONCOUNT; ++cnt) {
|
|
|
|
if (optlist[cnt].type != OPT_STR ||
|
2013-08-11 09:44:58 +00:00
|
|
|
F_ISSET(&sp->opts[cnt], OPT_GLOBAL))
|
1996-11-01 06:45:43 +00:00
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* If never set, or already failed, NULL out the entries --
|
|
|
|
* have to continue after failure, otherwise would have two
|
|
|
|
* screens referencing the same memory.
|
|
|
|
*/
|
|
|
|
if (rval || O_STR(sp, cnt) == NULL) {
|
|
|
|
o_set(sp, cnt, OS_NOFREE | OS_STR, NULL, 0);
|
|
|
|
o_set(sp, cnt, OS_DEF | OS_NOFREE | OS_STR, NULL, 0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the current string. */
|
|
|
|
if (o_set(sp, cnt, OS_NOFREE | OS_STRDUP, O_STR(sp, cnt), 0)) {
|
|
|
|
o_set(sp, cnt, OS_DEF | OS_NOFREE | OS_STR, NULL, 0);
|
|
|
|
goto nomem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the default string. */
|
|
|
|
if (O_D_STR(sp, cnt) != NULL && o_set(sp, cnt,
|
|
|
|
OS_DEF | OS_NOFREE | OS_STRDUP, O_D_STR(sp, cnt), 0)) {
|
|
|
|
nomem: msgq(orig, M_SYSERR, NULL);
|
|
|
|
rval = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* opts_free --
|
|
|
|
* Free all option strings
|
|
|
|
*
|
2015-04-10 13:26:05 +00:00
|
|
|
* PUBLIC: void opts_free(SCR *);
|
1996-11-01 06:45:43 +00:00
|
|
|
*/
|
|
|
|
void
|
2013-08-11 09:44:58 +00:00
|
|
|
opts_free(SCR *sp)
|
1996-11-01 06:45:43 +00:00
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
for (cnt = 0; cnt < O_OPTIONCOUNT; ++cnt) {
|
|
|
|
if (optlist[cnt].type != OPT_STR ||
|
2013-08-11 09:44:58 +00:00
|
|
|
F_ISSET(&sp->opts[cnt], OPT_GLOBAL))
|
1996-11-01 06:45:43 +00:00
|
|
|
continue;
|
2020-09-09 07:57:59 +00:00
|
|
|
free(O_STR(sp, cnt));
|
|
|
|
free(O_D_STR(sp, cnt));
|
1996-11-01 06:45:43 +00:00
|
|
|
}
|
|
|
|
}
|