home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / EDITOR / NVI179B / NVI179B.ZIP / common / options.c < prev    next >
C/C++ Source or Header  |  1997-06-29  |  30KB  |  1,162 lines

  1. /*-
  2.  * Copyright (c) 1991, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  * Copyright (c) 1991, 1993, 1994, 1995, 1996
  5.  *    Keith Bostic.  All rights reserved.
  6.  *
  7.  * See the LICENSE file for redistribution information.
  8.  */
  9.  
  10. #include "config.h"
  11.  
  12. #ifndef lint
  13. static const char sccsid[] = "@(#)options.c    10.51 (Berkeley) 10/14/96";
  14. #endif /* not lint */
  15.  
  16. #include <sys/types.h>
  17. #include <sys/queue.h>
  18. #include <sys/stat.h>
  19. #include <sys/time.h>
  20.  
  21. #include <bitstring.h>
  22. #include <ctype.h>
  23. #include <errno.h>
  24. #include <limits.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29.  
  30. #include "common.h"
  31. #include "../vi/vi.h"
  32. #include "pathnames.h"
  33.  
  34. static int          opts_abbcmp __P((const void *, const void *));
  35. static int          opts_cmp __P((const void *, const void *));
  36. static int          opts_print __P((SCR *, OPTLIST const *));
  37.  
  38. /*
  39.  * O'Reilly noted options and abbreviations are from "Learning the VI Editor",
  40.  * Fifth Edition, May 1992.  There's no way of knowing what systems they are
  41.  * actually from.
  42.  *
  43.  * HPUX noted options and abbreviations are from "The Ultimate Guide to the
  44.  * VI and EX Text Editors", 1990.
  45.  */
  46. OPTLIST const optlist[] = {
  47. /* O_ALTWERASE      4.4BSD */
  48.     {"altwerase",    f_altwerase,    OPT_0BOOL,    0},
  49. /* O_AUTOINDENT        4BSD */
  50.     {"autoindent",    NULL,        OPT_0BOOL,    0},
  51. /* O_AUTOPRINT        4BSD */
  52.     {"autoprint",    NULL,        OPT_1BOOL,    0},
  53. /* O_AUTOWRITE        4BSD */
  54.     {"autowrite",    NULL,        OPT_0BOOL,    0},
  55. /* O_BACKUP      4.4BSD */
  56.     {"backup",    NULL,        OPT_STR,    0},
  57. /* O_BEAUTIFY        4BSD */
  58.     {"beautify",    NULL,        OPT_0BOOL,    0},
  59. /* O_CDPATH      4.4BSD */
  60.     {"cdpath",    NULL,        OPT_STR,    0},
  61. /* O_CEDIT      4.4BSD */
  62.     {"cedit",    NULL,        OPT_STR,    0},
  63. /* O_COLUMNS      4.4BSD */
  64.     {"columns",    f_columns,    OPT_NUM,    OPT_NOSAVE},
  65. /* O_COMMENT      4.4BSD */
  66.     {"comment",    NULL,        OPT_0BOOL,    0},
  67. /* O_DIRECTORY        4BSD */
  68.     {"directory",    NULL,        OPT_STR,    0},
  69. /* O_EDCOMPATIBLE   4BSD */
  70.     {"edcompatible",NULL,        OPT_0BOOL,    0},
  71. /* O_ESCAPETIME      4.4BSD */
  72.     {"escapetime",    NULL,        OPT_NUM,    0},
  73. /* O_ERRORBELLS        4BSD */
  74.     {"errorbells",    NULL,        OPT_0BOOL,    0},
  75. /* O_EXRC    System V (undocumented) */
  76.     {"exrc",    NULL,        OPT_0BOOL,    0},
  77. /* O_EXTENDED      4.4BSD */
  78.     {"extended",    f_recompile,    OPT_0BOOL,    0},
  79. /* O_FILEC      4.4BSD */
  80.     {"filec",    NULL,        OPT_STR,    0},
  81. /* O_FLASH        HPUX */
  82.     {"flash",    NULL,        OPT_1BOOL,    0},
  83. /* O_HARDTABS        4BSD */
  84.     {"hardtabs",    NULL,        OPT_NUM,    0},
  85. /* O_ICLOWER      4.4BSD */
  86.     {"iclower",    f_recompile,    OPT_0BOOL,    0},
  87. /* O_IGNORECASE        4BSD */
  88.     {"ignorecase",    f_recompile,    OPT_0BOOL,    0},
  89. /* O_KEYTIME      4.4BSD */
  90.     {"keytime",    NULL,        OPT_NUM,    0},
  91. /* O_LEFTRIGHT      4.4BSD */
  92.     {"leftright",    f_reformat,    OPT_0BOOL,    0},
  93. /* O_LINES      4.4BSD */
  94.     {"lines",    f_lines,    OPT_NUM,    OPT_NOSAVE},
  95. /* O_LISP        4BSD
  96.  *    XXX
  97.  *    When the lisp option is implemented, delete the OPT_NOSAVE flag,
  98.  *    so that :mkexrc dumps it.
  99.  */
  100.     {"lisp",    f_lisp,        OPT_0BOOL,    OPT_NOSAVE},
  101. /* O_LIST        4BSD */
  102.     {"list",    f_reformat,    OPT_0BOOL,    0},
  103. /* O_LOCKFILES      4.4BSD
  104.  *    XXX
  105.  *    Locking isn't reliable enough over NFS to require it, in addition,
  106.  *    it's a serious startup performance problem over some remote links.
  107.  */
  108.     {"lock",    NULL,        OPT_1BOOL,    0},
  109. /* O_MAGIC        4BSD */
  110.     {"magic",    NULL,        OPT_1BOOL,    0},
  111. /* O_MATCHTIME      4.4BSD */
  112.     {"matchtime",    NULL,        OPT_NUM,    0},
  113. /* O_MESG        4BSD */
  114.     {"mesg",    NULL,        OPT_1BOOL,    0},
  115. /* O_MODELINE        4BSD
  116.  *    !!!
  117.  *    This has been documented in historical systems as both "modeline"
  118.  *    and as "modelines".  Regardless of the name, this option represents
  119.  *    a security problem of mammoth proportions, not to mention a stunning
  120.  *    example of what your intro CS professor referred to as the perils of
  121.  *    mixing code and data.  Don't add it, or I will kill you.
  122.  */
  123.     {"modeline",    NULL,        OPT_0BOOL,    OPT_NOSET},
  124. /* O_MSGCAT      4.4BSD */
  125.     {"msgcat",    f_msgcat,    OPT_STR,    0},
  126. /* O_NOPRINT      4.4BSD */
  127.     {"noprint",    f_print,    OPT_STR,    0},
  128. /* O_NUMBER        4BSD */
  129.     {"number",    f_reformat,    OPT_0BOOL,    0},
  130. /* O_OCTAL      4.4BSD */
  131.     {"octal",    f_print,    OPT_0BOOL,    0},
  132. /* O_OPEN        4BSD */
  133.     {"open",    NULL,        OPT_1BOOL,    0},
  134. /* O_OPTIMIZE        4BSD */
  135.     {"optimize",    NULL,        OPT_1BOOL,    0},
  136. /* O_PARAGRAPHS        4BSD */
  137.     {"paragraphs",    f_paragraph,    OPT_STR,    0},
  138. /* O_PATH      4.4BSD */
  139.     {"path",    NULL,        OPT_STR,    0},
  140. /* O_PRINT      4.4BSD */
  141.     {"print",    f_print,    OPT_STR,    0},
  142. /* O_PROMPT        4BSD */
  143.     {"prompt",    NULL,        OPT_1BOOL,    0},
  144. /* O_READONLY        4BSD (undocumented) */
  145.     {"readonly",    f_readonly,    OPT_0BOOL,    OPT_ALWAYS},
  146. /* O_RECDIR      4.4BSD */
  147.     {"recdir",    NULL,        OPT_STR,    0},
  148. /* O_REDRAW        4BSD */
  149.     {"redraw",    NULL,        OPT_0BOOL,    0},
  150. /* O_REMAP        4BSD */
  151.     {"remap",    NULL,        OPT_1BOOL,    0},
  152. /* O_REPORT        4BSD */
  153.     {"report",    NULL,        OPT_NUM,    0},
  154. /* O_RULER      4.4BSD */
  155.     {"ruler",    NULL,        OPT_0BOOL,    0},
  156. /* O_SCROLL        4BSD */
  157.     {"scroll",    NULL,        OPT_NUM,    0},
  158. /* O_SEARCHINCR      4.4BSD */
  159.     {"searchincr",    NULL,        OPT_0BOOL,    0},
  160. /* O_SECTIONS        4BSD */
  161.     {"sections",    f_section,    OPT_STR,    0},
  162. /* O_SECURE      4.4BSD */
  163.     {"secure",    NULL,        OPT_0BOOL,    OPT_NOUNSET},
  164. /* O_SHELL        4BSD */
  165.     {"shell",    NULL,        OPT_STR,    0},
  166. /* O_SHELLMETA      4.4BSD */
  167.     {"shellmeta",    NULL,        OPT_STR,    0},
  168. /* O_SHIFTWIDTH        4BSD */
  169.     {"shiftwidth",    NULL,        OPT_NUM,    OPT_NOZERO},
  170. /* O_SHOWMATCH        4BSD */
  171.     {"showmatch",    NULL,        OPT_0BOOL,    0},
  172. /* O_SHOWMODE      4.4BSD */
  173.     {"showmode",    NULL,        OPT_0BOOL,    0},
  174. /* O_SIDESCROLL      4.4BSD */
  175.     {"sidescroll",    NULL,        OPT_NUM,    OPT_NOZERO},
  176. /* O_SLOWOPEN        4BSD  */
  177.     {"slowopen",    NULL,        OPT_0BOOL,    0},
  178. /* O_SOURCEANY        4BSD (undocumented)
  179.  *    !!!
  180.  *    Historic vi, on startup, source'd $HOME/.exrc and ./.exrc, if they
  181.  *    were owned by the user.  The sourceany option was an undocumented
  182.  *    feature of historic vi which permitted the startup source'ing of
  183.  *    .exrc files the user didn't own.  This is an obvious security problem,
  184.  *    and we ignore the option.
  185.  */
  186.     {"sourceany",    NULL,        OPT_0BOOL,    OPT_NOSET},
  187. /* O_TABSTOP        4BSD */
  188.     {"tabstop",    f_reformat,    OPT_NUM,    OPT_NOZERO},
  189. /* O_TAGLENGTH        4BSD */
  190.     {"taglength",    NULL,        OPT_NUM,    0},
  191. /* O_TAGS        4BSD */
  192.     {"tags",    NULL,        OPT_STR,    0},
  193. /* O_TERM        4BSD
  194.  *    !!!
  195.  *    By default, the historic vi always displayed information about two
  196.  *    options, redraw and term.  Term seems sufficient.
  197.  */
  198.     {"term",    NULL,        OPT_STR,    OPT_ADISP|OPT_NOSAVE},
  199. /* O_TERSE        4BSD */
  200.     {"terse",    NULL,        OPT_0BOOL,    0},
  201. /* O_TILDEOP      4.4BSD */
  202.     {"tildeop",    NULL,        OPT_0BOOL,    0},
  203. /* O_TIMEOUT        4BSD (undocumented) */
  204.     {"timeout",    NULL,        OPT_1BOOL,    0},
  205. /* O_TTYWERASE      4.4BSD */
  206.     {"ttywerase",    f_ttywerase,    OPT_0BOOL,    0},
  207. /* O_VERBOSE      4.4BSD */
  208.     {"verbose",    NULL,        OPT_0BOOL,    0},
  209. /* O_W1200        4BSD */
  210.     {"w1200",    f_w1200,    OPT_NUM,    OPT_NDISP|OPT_NOSAVE},
  211. /* O_W300        4BSD */
  212.     {"w300",    f_w300,        OPT_NUM,    OPT_NDISP|OPT_NOSAVE},
  213. /* O_W9600        4BSD */
  214.     {"w9600",    f_w9600,    OPT_NUM,    OPT_NDISP|OPT_NOSAVE},
  215. /* O_WARN        4BSD */
  216.     {"warn",    NULL,        OPT_1BOOL,    0},
  217. /* O_WINDOW        4BSD */
  218.     {"window",    f_window,    OPT_NUM,    0},
  219. /* O_WINDOWNAME        4BSD */
  220.     {"windowname",    NULL,        OPT_0BOOL,    0},
  221. /* O_WRAPLEN      4.4BSD */
  222.     {"wraplen",    NULL,        OPT_NUM,    0},
  223. /* O_WRAPMARGIN        4BSD */
  224.     {"wrapmargin",    NULL,        OPT_NUM,    0},
  225. /* O_WRAPSCAN        4BSD */
  226.     {"wrapscan",    NULL,        OPT_1BOOL,    0},
  227. /* O_WRITEANY        4BSD */
  228.     {"writeany",    NULL,        OPT_0BOOL,    0},
  229.     {NULL},
  230. };
  231.  
  232. typedef struct abbrev {
  233.         char *name;
  234.         int offset;
  235. } OABBREV;
  236.  
  237. static OABBREV const abbrev[] = {
  238.     {"ai",        O_AUTOINDENT},        /*     4BSD */
  239.     {"ap",        O_AUTOPRINT},        /*     4BSD */
  240.     {"aw",        O_AUTOWRITE},        /*     4BSD */
  241.     {"bf",        O_BEAUTIFY},        /*     4BSD */
  242.     {"co",        O_COLUMNS},        /*   4.4BSD */
  243.     {"dir",        O_DIRECTORY},        /*     4BSD */
  244.     {"eb",        O_ERRORBELLS},        /*     4BSD */
  245.     {"ed",        O_EDCOMPATIBLE},    /*     4BSD */
  246.     {"ex",        O_EXRC},        /* System V (undocumented) */
  247.     {"ht",        O_HARDTABS},        /*     4BSD */
  248.     {"ic",        O_IGNORECASE},        /*     4BSD */
  249.     {"li",        O_LINES},        /*   4.4BSD */
  250.     {"modelines",    O_MODELINE},        /*     HPUX */
  251.     {"nu",        O_NUMBER},        /*     4BSD */
  252.     {"opt",        O_OPTIMIZE},        /*     4BSD */
  253.     {"para",    O_PARAGRAPHS},        /*     4BSD */
  254.     {"re",        O_REDRAW},        /* O'Reilly */
  255.     {"ro",        O_READONLY},        /*     4BSD (undocumented) */
  256.     {"scr",        O_SCROLL},        /*     4BSD (undocumented) */
  257.     {"sect",    O_SECTIONS},        /* O'Reilly */
  258.     {"sh",        O_SHELL},        /*     4BSD */
  259.     {"slow",    O_SLOWOPEN},        /*     4BSD */
  260.     {"sm",        O_SHOWMATCH},        /*     4BSD */
  261.     {"smd",        O_SHOWMODE},        /*     4BSD */
  262.     {"sw",        O_SHIFTWIDTH},        /*     4BSD */
  263.     {"tag",        O_TAGS},        /*     4BSD (undocumented) */
  264.     {"tl",        O_TAGLENGTH},        /*     4BSD */
  265.     {"to",        O_TIMEOUT},        /*     4BSD (undocumented) */
  266.     {"ts",        O_TABSTOP},        /*     4BSD */
  267.     {"tty",        O_TERM},        /*     4BSD (undocumented) */
  268.     {"ttytype",    O_TERM},        /*     4BSD (undocumented) */
  269.     {"w",        O_WINDOW},        /* O'Reilly */
  270.     {"wa",        O_WRITEANY},        /*     4BSD */
  271.     {"wi",        O_WINDOW},        /*     4BSD (undocumented) */
  272.     {"wl",        O_WRAPLEN},        /*   4.4BSD */
  273.     {"wm",        O_WRAPMARGIN},        /*     4BSD */
  274.     {"ws",        O_WRAPSCAN},        /*     4BSD */
  275.     {NULL},
  276. };
  277.  
  278. /*
  279.  * opts_init --
  280.  *    Initialize some of the options.
  281.  *
  282.  * PUBLIC: int opts_init __P((SCR *, int *));
  283.  */
  284. int
  285. opts_init(sp, oargs)
  286.     SCR *sp;
  287.     int *oargs;
  288. {
  289.     ARGS *argv[2], a, b;
  290.     OPTLIST const *op;
  291.     u_long v;
  292.     int cnt, optindx;
  293.     char *s, b1[1024];
  294.  
  295.     a.bp = b1;
  296.     b.bp = NULL;
  297.     a.len = b.len = 0;
  298.     argv[0] = &a;
  299.     argv[1] = &b;
  300.  
  301.     /* Set numeric and string default values. */
  302. #define    OI(indx, str) {                            \
  303.     if (str != b1)        /* GCC puts strings in text-space. */    \
  304.         (void)strcpy(b1, str);                    \
  305.     a.len = strlen(b1);                        \
  306.     if (opts_set(sp, argv, NULL)) {                    \
  307.          optindx = indx;                    \
  308.         goto err;                        \
  309.     }                                \
  310. }
  311.     /*
  312.      * Indirect global options to global space.  Specifically, set up
  313.      * terminal, lines, columns first, they're used by other options.
  314.      * Note, don't set the flags until we've set up the indirection.
  315.      */
  316.     if (o_set(sp, O_TERM, 0, NULL, GO_TERM))
  317.         goto err;
  318.     F_SET(&sp->opts[O_TERM], OPT_GLOBAL);
  319.     if (o_set(sp, O_LINES, 0, NULL, GO_LINES))
  320.         goto err;
  321.     F_SET(&sp->opts[O_LINES], OPT_GLOBAL);
  322.     if (o_set(sp, O_COLUMNS, 0, NULL, GO_COLUMNS))
  323.         goto err;
  324.     F_SET(&sp->opts[O_COLUMNS], OPT_GLOBAL);
  325.     if (o_set(sp, O_SECURE, 0, NULL, GO_SECURE))
  326.         goto err;
  327.     F_SET(&sp->opts[O_SECURE], OPT_GLOBAL);
  328.  
  329.     /* Initialize string values. */
  330. #if VI_DOSISH
  331.     (void)snprintf(b1, sizeof(b1),
  332.         "cdpath=%s", (s = getenv("CDPATH")) == NULL ? ";" : s);
  333. #else
  334.     (void)snprintf(b1, sizeof(b1),
  335.         "cdpath=%s", (s = getenv("CDPATH")) == NULL ? ":" : s);
  336. #endif
  337.     OI(O_CDPATH, b1);
  338.  
  339.     /*
  340.      * !!!
  341.      * Vi historically stored temporary files in /var/tmp.  We store them
  342.      * in /tmp by default, hoping it's a memory based file system.  There
  343.      * are two ways to change this -- the user can set either the directory
  344.      * option or the TMPDIR environmental variable.
  345.      */
  346.     (void)snprintf(b1, sizeof(b1),
  347.         "directory=%s", (s = getenv("TMPDIR")) == NULL ? _PATH_TMP : s);
  348.     OI(O_DIRECTORY, b1);
  349.     OI(O_ESCAPETIME, "escapetime=1");
  350.     OI(O_KEYTIME, "keytime=6");
  351.     OI(O_MATCHTIME, "matchtime=7");
  352.     (void)snprintf(b1, sizeof(b1), "msgcat=%s", _PATH_MSGCAT);
  353.     OI(O_MSGCAT, b1);
  354.     OI(O_REPORT, "report=5");
  355.     OI(O_PARAGRAPHS, "paragraphs=IPLPPPQPP LIpplpipbp");
  356.     (void)snprintf(b1, sizeof(b1), "path=%s", "");
  357.     OI(O_PATH, b1);
  358.     (void)snprintf(b1, sizeof(b1), "recdir=%s", _PATH_PRESERVE);
  359.     OI(O_RECDIR, b1);
  360.     OI(O_SECTIONS, "sections=NHSHH HUnhsh");
  361. #if VI_DOSISH
  362.     /*
  363.      * Poorly-designed EMX hosts use COMSPEC for everything; more modern
  364.      * ones allow you to specify a noninteractive shell with known
  365.      * semantics and an interactive one that does whatever.  Not even Unix
  366.      * gets that one right, although it's mitigated by the guarantee that
  367.      * /bin/sh is always there...  (Until it isn't; I dislike hardcoded
  368.      * pathnames.)
  369.      */
  370.     s = getenv("OS2_SHELL");
  371.     if (!s) s = getenv("COMSPEC");
  372.     if (!s) s = _PATH_BSHELL;
  373.     (void)snprintf(b1, sizeof(b1), "shell=%s", s);
  374. #else
  375.     (void)snprintf(b1, sizeof(b1),
  376.         "shell=%s", (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s);
  377. #endif
  378.     OI(O_SHELL, b1);
  379.     OI(O_SHELLMETA, "shellmeta=~{[*?$`'\"\\");
  380.     OI(O_SHIFTWIDTH, "shiftwidth=8");
  381.     OI(O_SIDESCROLL, "sidescroll=16");
  382.     OI(O_TABSTOP, "tabstop=8");
  383.     (void)snprintf(b1, sizeof(b1), "tags=%s", _PATH_TAGS);
  384.     OI(O_TAGS, b1);
  385.  
  386.     /*
  387.      * XXX
  388.      * Initialize O_SCROLL here, after term; initializing term should
  389.      * have created a LINES/COLUMNS value.
  390.      */
  391.     if ((v = (O_VAL(sp, O_LINES) - 1) / 2) == 0)
  392.         v = 1;
  393.     (void)snprintf(b1, sizeof(b1), "scroll=%ld", v);
  394.     OI(O_SCROLL, b1);
  395.  
  396.     /*
  397.      * The default window option values are:
  398.      *        8 if baud rate <=  600
  399.      *           16 if baud rate <= 1200
  400.      *    LINES - 1 if baud rate  > 1200
  401.      *
  402.      * Note, the windows option code will correct any too-large value
  403.      * or when the O_LINES value is 1.
  404.      */
  405.     if (sp->gp->scr_baud(sp, &v))
  406.         return (1);
  407.     if (v <= 600)
  408.         v = 8;
  409.     else if (v <= 1200)
  410.         v = 16;
  411.     else
  412.         v = O_VAL(sp, O_LINES) - 1;
  413.     (void)snprintf(b1, sizeof(b1), "window=%lu", v);
  414.     OI(O_WINDOW, b1);
  415.  
  416.     /*
  417.      * Set boolean default values, and copy all settings into the default
  418.      * information.  OS_NOFREE is set, we're copying, not replacing.
  419.      */
  420.     for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt)
  421.         switch (op->type) {
  422.         case OPT_0BOOL:
  423.             break;
  424.         case OPT_1BOOL:
  425.             O_SET(sp, cnt);
  426.             O_D_SET(sp, cnt);
  427.             break;
  428.         case OPT_NUM:
  429.             o_set(sp, cnt, OS_DEF, NULL, O_VAL(sp, cnt));
  430.             break;
  431.         case OPT_STR:
  432.             if (O_STR(sp, cnt) != NULL && o_set(sp, cnt,
  433.                 OS_DEF | OS_NOFREE | OS_STRDUP, O_STR(sp, cnt), 0))
  434.                 goto err;
  435.             break;
  436.         default:
  437.             abort();
  438.         }
  439.  
  440.     /*
  441.      * !!!
  442.      * Some options can be initialized by the command name or the
  443.      * command-line arguments.  They don't set the default values,
  444.      * it's historic practice.
  445.      */
  446.     for (; *oargs != -1; ++oargs)
  447.         OI(*oargs, optlist[*oargs].name);
  448.     return (0);
  449. #undef OI
  450.  
  451. err:    msgq(sp, M_ERR,
  452.         "031|Unable to set default %s option", optlist[optindx].name);
  453.     return (1);
  454. }
  455.  
  456. /*
  457.  * opts_set --
  458.  *    Change the values of one or more options.
  459.  *
  460.  * PUBLIC: int opts_set __P((SCR *, ARGS *[], char *));
  461.  */
  462. int
  463. opts_set(sp, argv, usage)
  464.     SCR *sp;
  465.     ARGS *argv[];
  466.     char *usage;
  467. {
  468.     enum optdisp disp;
  469.     enum nresult nret;
  470.     OPTLIST const *op;
  471.     OPTION *spo;
  472.     u_long value, turnoff;
  473.     int ch, equals, nf, nf2, offset, qmark, rval;
  474.     char *endp, *name, *p, *sep, *t;
  475.  
  476.     disp = NO_DISPLAY;
  477.     for (rval = 0; argv[0]->len != 0; ++argv) {
  478.         /*
  479.          * The historic vi dumped the options for each occurrence of
  480.          * "all" in the set list.  Puhleeze.
  481.          */
  482.         if (!strcmp(argv[0]->bp, "all")) {
  483.             disp = ALL_DISPLAY;
  484.             continue;
  485.         }
  486.  
  487.         /* Find equals sign or question mark. */
  488.         for (sep = NULL, equals = qmark = 0,
  489.             p = name = argv[0]->bp; (ch = *p) != '\0'; ++p)
  490.             if (ch == '=' || ch == '?') {
  491.                 if (p == name) {
  492.                     if (usage != NULL)
  493.                         msgq(sp, M_ERR,
  494.                             "032|Usage: %s", usage);
  495.                     return (1);
  496.                 }
  497.                 sep = p;
  498.                 if (ch == '=')
  499.                     equals = 1;
  500.                 else
  501.                     qmark = 1;
  502.                 break;
  503.             }
  504.  
  505.         turnoff = 0;
  506.         op = NULL;
  507.         if (sep != NULL)
  508.             *sep++ = '\0';
  509.  
  510.         /* Search for the name, then name without any leading "no". */
  511.         if ((op = opts_search(name)) == NULL &&
  512.             name[0] == 'n' && name[1] == 'o') {
  513.             turnoff = 1;
  514.             name += 2;
  515.             op = opts_search(name);
  516.         }
  517.         if (op == NULL) {
  518.             opts_nomatch(sp, name);
  519.             rval = 1;
  520.             continue;
  521.         }
  522.  
  523.         /* Find current option values. */
  524.         offset = op - optlist;
  525.         spo = sp->opts + offset;
  526.  
  527.         /*
  528.          * !!!
  529.          * Historically, the question mark could be a separate
  530.          * argument.
  531.          */
  532.         if (!equals && !qmark &&
  533.             argv[1]->len == 1 && argv[1]->bp[0] == '?') {
  534.             ++argv;
  535.             qmark = 1;
  536.         }
  537.  
  538.         /* Set name, value. */
  539.         switch (op->type) {
  540.         case OPT_0BOOL:
  541.         case OPT_1BOOL:
  542.             /* Some options may not be reset. */
  543.             if (F_ISSET(op, OPT_NOUNSET) && turnoff) {
  544.                 msgq_str(sp, M_ERR, name,
  545.                 "291|set: the %s option may not be turned off");
  546.                 rval = 1;
  547.                 break;
  548.             }
  549.  
  550.             /* Some options may not be set. */
  551.             if (F_ISSET(op, OPT_NOSET) && !turnoff) {
  552.                 msgq_str(sp, M_ERR, name,
  553.                 "313|set: the %s option may never be turned on");
  554.                 rval = 1;
  555.                 break;
  556.             }
  557.  
  558.             if (equals) {
  559.                 msgq_str(sp, M_ERR, name,
  560.                 "034|set: [no]%s option doesn't take a value");
  561.                 rval = 1;
  562.                 break;
  563.             }
  564.             if (qmark) {
  565.                 if (!disp)
  566.                     disp = SELECT_DISPLAY;
  567.                 F_SET(spo, OPT_SELECTED);
  568.                 break;
  569.             }
  570.  
  571.             /*
  572.              * Do nothing if the value is unchanged, the underlying
  573.              * functions can be expensive.
  574.              */
  575.             if (!F_ISSET(op, OPT_ALWAYS))
  576.                 if (turnoff) {
  577.                     if (!O_ISSET(sp, offset))
  578.                         break;
  579.                 } else {
  580.                     if (O_ISSET(sp, offset))
  581.                         break;
  582.                 }
  583.  
  584.             /* Report to subsystems. */
  585.             if (op->func != NULL &&
  586.                 op->func(sp, spo, NULL, &turnoff) ||
  587.                 ex_optchange(sp, offset, NULL, &turnoff) ||
  588.                 v_optchange(sp, offset, NULL, &turnoff) ||
  589.                 sp->gp->scr_optchange(sp, offset, NULL, &turnoff)) {
  590.                 rval = 1;
  591.                 break;
  592.             }
  593.  
  594.             /* Set the value. */
  595.             if (turnoff)
  596.                 O_CLR(sp, offset);
  597.             else
  598.                 O_SET(sp, offset);
  599.             break;
  600.         case OPT_NUM:
  601.             if (turnoff) {
  602.                 msgq_str(sp, M_ERR, name,
  603.                     "035|set: %s option isn't a boolean");
  604.                 rval = 1;
  605.                 break;
  606.             }
  607.             if (qmark || !equals) {
  608.                 if (!disp)
  609.                     disp = SELECT_DISPLAY;
  610.                 F_SET(spo, OPT_SELECTED);
  611.                 break;
  612.             }
  613.  
  614.             if (!isdigit(sep[0]))
  615.                 goto badnum;
  616.             if ((nret =
  617.                 nget_uslong(&value, sep, &endp, 10)) != NUM_OK) {
  618.                 p = msg_print(sp, name, &nf);
  619.                 t = msg_print(sp, sep, &nf2);
  620.                 switch (nret) {
  621.                 case NUM_ERR:
  622.                     msgq(sp, M_SYSERR,
  623.                         "036|set: %s option: %s", p, t);
  624.                     break;
  625.                 case NUM_OVER:
  626.                     msgq(sp, M_ERR,
  627.                 "037|set: %s option: %s: value overflow", p, t);
  628.                     break;
  629.                 case NUM_OK:
  630.                 case NUM_UNDER:
  631.                     abort();
  632.                 }
  633.                 if (nf)
  634.                     FREE_SPACE(sp, p, 0);
  635.                 if (nf2)
  636.                     FREE_SPACE(sp, t, 0);
  637.                 rval = 1;
  638.                 break;
  639.             }
  640.             if (*endp && !isblank(*endp)) {
  641. badnum:                p = msg_print(sp, name, &nf);
  642.                 t = msg_print(sp, sep, &nf2);
  643.                 msgq(sp, M_ERR,
  644.             "038|set: %s option: %s is an illegal number", p, t);
  645.                 if (nf)
  646.                     FREE_SPACE(sp, p, 0);
  647.                 if (nf2)
  648.                     FREE_SPACE(sp, t, 0);
  649.                 rval = 1;
  650.                 break;
  651.             }
  652.  
  653.             /* Some options may never be set to zero. */
  654.             if (F_ISSET(op, OPT_NOZERO) && value == 0) {
  655.                 msgq_str(sp, M_ERR, name,
  656.                 "314|set: the %s option may never be set to 0");
  657.                 rval = 1;
  658.                 break;
  659.             }
  660.  
  661.             /*
  662.              * Do nothing if the value is unchanged, the underlying
  663.              * functions can be expensive.
  664.              */
  665.             if (!F_ISSET(op, OPT_ALWAYS) &&
  666.                 O_VAL(sp, offset) == value)
  667.                 break;
  668.  
  669.             /* Report to subsystems. */
  670.             if (op->func != NULL &&
  671.                 op->func(sp, spo, sep, &value) ||
  672.                 ex_optchange(sp, offset, sep, &value) ||
  673.                 v_optchange(sp, offset, sep, &value) ||
  674.                 sp->gp->scr_optchange(sp, offset, sep, &value)) {
  675.                 rval = 1;
  676.                 break;
  677.             }
  678.  
  679.             /* Set the value. */
  680.             if (o_set(sp, offset, 0, NULL, value))
  681.                 rval = 1;
  682.             break;
  683.         case OPT_STR:
  684.             if (turnoff) {
  685.                 msgq_str(sp, M_ERR, name,
  686.                     "039|set: %s option isn't a boolean");
  687.                 rval = 1;
  688.                 break;
  689.             }
  690.             if (qmark || !equals) {
  691.                 if (!disp)
  692.                     disp = SELECT_DISPLAY;
  693.                 F_SET(spo, OPT_SELECTED);
  694.                 break;
  695.             }
  696.  
  697.             /*
  698.              * Do nothing if the value is unchanged, the underlying
  699.              * functions can be expensive.
  700.              */
  701.             if (!F_ISSET(op, OPT_ALWAYS) &&
  702.                 O_STR(sp, offset) != NULL &&
  703.                 !strcmp(O_STR(sp, offset), sep))
  704.                 break;
  705.  
  706.             /* Report to subsystems. */
  707.             if (op->func != NULL &&
  708.                 op->func(sp, spo, sep, NULL) ||
  709.                 ex_optchange(sp, offset, sep, NULL) ||
  710.                 v_optchange(sp, offset, sep, NULL) ||
  711.                 sp->gp->scr_optchange(sp, offset, sep, NULL)) {
  712.                 rval = 1;
  713.                 break;
  714.             }
  715.  
  716.             /* Set the value. */
  717.             if (o_set(sp, offset, OS_STRDUP, sep, 0))
  718.                 rval = 1;
  719.             break;
  720.         default:
  721.             abort();
  722.         }
  723.     }
  724.     if (disp != NO_DISPLAY)
  725.         opts_dump(sp, disp);
  726.     return (rval);
  727. }
  728.  
  729. /*
  730.  * o_set --
  731.  *    Set an option's value.
  732.  *
  733.  * PUBLIC: int o_set __P((SCR *, int, u_int, char *, u_long));
  734.  */
  735. int
  736. o_set(sp, opt, flags, str, val)
  737.     SCR *sp;
  738.     int opt;
  739.     u_int flags;
  740.     char *str;
  741.     u_long val;
  742. {
  743.     OPTION *op;
  744.  
  745.     /* Set a pointer to the options area. */
  746.     op = F_ISSET(&sp->opts[opt], OPT_GLOBAL) ?
  747.         &sp->gp->opts[sp->opts[opt].o_cur.val] : &sp->opts[opt];
  748.  
  749.     /* Copy the string, if requested. */
  750.     if (LF_ISSET(OS_STRDUP) && (str = strdup(str)) == NULL) {
  751.         msgq(sp, M_SYSERR, NULL);
  752.         return (1);
  753.     }
  754.  
  755.     /* Free the previous string, if requested, and set the value. */
  756.     if LF_ISSET(OS_DEF)
  757.         if (LF_ISSET(OS_STR | OS_STRDUP)) {
  758.             if (!LF_ISSET(OS_NOFREE) && op->o_def.str != NULL)
  759.                 free(op->o_def.str);
  760.             op->o_def.str = str;
  761.         } else
  762.             op->o_def.val = val;
  763.     else
  764.         if (LF_ISSET(OS_STR | OS_STRDUP)) {
  765.             if (!LF_ISSET(OS_NOFREE) && op->o_cur.str != NULL)
  766.                 free(op->o_cur.str);
  767.             op->o_cur.str = str;
  768.         } else
  769.             op->o_cur.val = val;
  770.     return (0);
  771. }
  772.  
  773. /*
  774.  * opts_empty --
  775.  *    Return 1 if the string option is invalid, 0 if it's OK.
  776.  *
  777.  * PUBLIC: int opts_empty __P((SCR *, int, int));
  778.  */
  779. int
  780. opts_empty(sp, off, silent)
  781.     SCR *sp;
  782.     int off, silent;
  783. {
  784.     char *p;
  785.  
  786.     if ((p = O_STR(sp, off)) == NULL || p[0] == '\0') {
  787.         if (!silent)
  788.             msgq_str(sp, M_ERR, optlist[off].name,
  789.                 "305|No %s edit option specified");
  790.         return (1);
  791.     }
  792.     return (0);
  793. }
  794.  
  795. /*
  796.  * opts_dump --
  797.  *    List the current values of selected options.
  798.  *
  799.  * PUBLIC: void opts_dump __P((SCR *, enum optdisp));
  800.  */
  801. void
  802. opts_dump(sp, type)
  803.     SCR *sp;
  804.     enum optdisp type;
  805. {
  806.     OPTLIST const *op;
  807.     int base, b_num, cnt, col, colwidth, curlen, s_num;
  808.     int numcols, numrows, row;
  809.     int b_op[O_OPTIONCOUNT], s_op[O_OPTIONCOUNT];
  810.     char nbuf[20];
  811.  
  812.     /*
  813.      * Options are output in two groups -- those that fit in a column and
  814.      * those that don't.  Output is done on 6 character "tab" boundaries
  815.      * for no particular reason.  (Since we don't output tab characters,
  816.      * we can ignore the terminal's tab settings.)  Ignore the user's tab
  817.      * setting because we have no idea how reasonable it is.
  818.      *
  819.      * Find a column width we can live with, testing from 10 columns to 1.
  820.      */
  821.     for (numcols = 10; numcols > 1; --numcols) {
  822.         colwidth = sp->cols / numcols & ~(STANDARD_TAB - 1);
  823.         if (colwidth >= 10) {
  824.             colwidth =
  825.                 (colwidth + STANDARD_TAB) & ~(STANDARD_TAB - 1);
  826.             numcols = sp->cols / colwidth;
  827.             break;
  828.         }
  829.         colwidth = 0;
  830.     }
  831.  
  832.     /*
  833.      * Get the set of options to list, entering them into
  834.      * the column list or the overflow list.
  835.      */
  836.     for (b_num = s_num = 0, op = optlist; op->name != NULL; ++op) {
  837.         cnt = op - optlist;
  838.  
  839.         /* If OPT_NDISP set, it's never displayed. */
  840.         if (F_ISSET(op, OPT_NDISP))
  841.             continue;
  842.  
  843.         switch (type) {
  844.         case ALL_DISPLAY:        /* Display all. */
  845.             break;
  846.         case CHANGED_DISPLAY:        /* Display changed. */
  847.             /* If OPT_ADISP set, it's always "changed". */
  848.             if (F_ISSET(op, OPT_ADISP))
  849.                 break;
  850.             switch (op->type) {
  851.             case OPT_0BOOL:
  852.             case OPT_1BOOL:
  853.             case OPT_NUM:
  854.                 if (O_VAL(sp, cnt) == O_D_VAL(sp, cnt))
  855.                     continue;
  856.                 break;
  857.             case OPT_STR:
  858.                 if (O_STR(sp, cnt) == O_D_STR(sp, cnt) ||
  859.                     O_D_STR(sp, cnt) != NULL &&
  860.                     !strcmp(O_STR(sp, cnt), O_D_STR(sp, cnt)))
  861.                     continue;
  862.                 break;
  863.             }
  864.             break;
  865.         case SELECT_DISPLAY:        /* Display selected. */
  866.             if (!F_ISSET(&sp->opts[cnt], OPT_SELECTED))
  867.                 continue;
  868.             break;
  869.         default:
  870.         case NO_DISPLAY:
  871.             abort();
  872.         }
  873.         F_CLR(&sp->opts[cnt], OPT_SELECTED);
  874.  
  875.         curlen = strlen(op->name);
  876.         switch (op->type) {
  877.         case OPT_0BOOL:
  878.         case OPT_1BOOL:
  879.             if (!O_ISSET(sp, cnt))
  880.                 curlen += 2;
  881.             break;
  882.         case OPT_NUM:
  883.             (void)snprintf(nbuf,
  884.                 sizeof(nbuf), "%ld", O_VAL(sp, cnt));
  885.             curlen += strlen(nbuf);
  886.             break;
  887.         case OPT_STR:
  888.             if (O_STR(sp, cnt) != NULL)
  889.                 curlen += strlen(O_STR(sp, cnt));
  890.             curlen += 3;
  891.             break;
  892.         }
  893.         /* Offset by 2 so there's a gap. */
  894.         if (curlen <= colwidth - 2)
  895.             s_op[s_num++] = cnt;
  896.         else
  897.             b_op[b_num++] = cnt;
  898.     }
  899.  
  900.     if (s_num > 0) {
  901.         /* Figure out the number of rows. */
  902.         if (s_num > numcols) {
  903.             numrows = s_num / numcols;
  904.             if (s_num % numcols)
  905.                 ++numrows;
  906.         } else
  907.             numrows = 1;
  908.  
  909.         /* Display the options in sorted order. */
  910.         for (row = 0; row < numrows;) {
  911.             for (base = row, col = 0; col < numcols; ++col) {
  912.                 cnt = opts_print(sp, &optlist[s_op[base]]);
  913.                 if ((base += numrows) >= s_num)
  914.                     break;
  915.                 (void)ex_printf(sp, "%*s",
  916.                     (int)(colwidth - cnt), "");
  917.             }
  918.             if (++row < numrows || b_num)
  919.                 (void)ex_puts(sp, "\n");
  920.         }
  921.     }
  922.  
  923.     for (row = 0; row < b_num;) {
  924.         (void)opts_print(sp, &optlist[b_op[row]]);
  925.         if (++row < b_num)
  926.             (void)ex_puts(sp, "\n");
  927.     }
  928.     (void)ex_puts(sp, "\n");
  929. }
  930.  
  931. /*
  932.  * opts_print --
  933.  *    Print out an option.
  934.  */
  935. static int
  936. opts_print(sp, op)
  937.     SCR *sp;
  938.     OPTLIST const *op;
  939. {
  940.     int curlen, offset;
  941.  
  942.     curlen = 0;
  943.     offset = op - optlist;
  944.     switch (op->type) {
  945.     case OPT_0BOOL:
  946.     case OPT_1BOOL:
  947.         curlen += ex_printf(sp,
  948.             "%s%s", O_ISSET(sp, offset) ? "" : "no", op->name);
  949.         break;
  950.     case OPT_NUM:
  951.         curlen += ex_printf(sp, "%s=%ld", op->name, O_VAL(sp, offset));
  952.         break;
  953.     case OPT_STR:
  954.         curlen += ex_printf(sp, "%s=\"%s\"", op->name,
  955.             O_STR(sp, offset) == NULL ? "" : O_STR(sp, offset));
  956.         break;
  957.     }
  958.     return (curlen);
  959. }
  960.  
  961. /*
  962.  * opts_save --
  963.  *    Write the current configuration to a file.
  964.  *
  965.  * PUBLIC: int opts_save __P((SCR *, FILE *));
  966.  */
  967. int
  968. opts_save(sp, fp)
  969.     SCR *sp;
  970.     FILE *fp;
  971. {
  972.     OPTLIST const *op;
  973.     int ch, cnt;
  974.     char *p;
  975.  
  976.     for (op = optlist; op->name != NULL; ++op) {
  977.         if (F_ISSET(op, OPT_NOSAVE))
  978.             continue;
  979.         cnt = op - optlist;
  980.         switch (op->type) {
  981.         case OPT_0BOOL:
  982.         case OPT_1BOOL:
  983.             if (O_ISSET(sp, cnt))
  984.                 (void)fprintf(fp, "set %s\n", op->name);
  985.             else
  986.                 (void)fprintf(fp, "set no%s\n", op->name);
  987.             break;
  988.         case OPT_NUM:
  989.             (void)fprintf(fp,
  990.                 "set %s=%-3ld\n", op->name, O_VAL(sp, cnt));
  991.             break;
  992.         case OPT_STR:
  993.             if (O_STR(sp, cnt) == NULL)
  994.                 break;
  995.             (void)fprintf(fp, "set ");
  996.             for (p = op->name; (ch = *p) != '\0'; ++p) {
  997.                 if (isblank(ch) || ch == '\\')
  998.                     (void)putc('\\', fp);
  999.                 (void)putc(ch, fp);
  1000.             }
  1001.             (void)putc('=', fp);
  1002.             for (p = O_STR(sp, cnt); (ch = *p) != '\0'; ++p) {
  1003.                 if (isblank(ch) || ch == '\\')
  1004.                     (void)putc('\\', fp);
  1005.                 (void)putc(ch, fp);
  1006.             }
  1007.             (void)putc('\n', fp);
  1008.             break;
  1009.         }
  1010.         if (ferror(fp)) {
  1011.             msgq(sp, M_SYSERR, NULL);
  1012.             return (1);
  1013.         }
  1014.     }
  1015.     return (0);
  1016. }
  1017.  
  1018. /* 
  1019.  * opts_search --
  1020.  *    Search for an option.
  1021.  *
  1022.  * PUBLIC: OPTLIST const *opts_search __P((char *));
  1023.  */
  1024. OPTLIST const *
  1025. opts_search(name)
  1026.     char *name;
  1027. {
  1028.     OPTLIST const *op, *found;
  1029.     OABBREV atmp, *ap;
  1030.     OPTLIST otmp;
  1031.     size_t len;
  1032.  
  1033.     /* Check list of abbreviations. */
  1034.     atmp.name = name;
  1035.     if ((ap = bsearch(&atmp, abbrev, sizeof(abbrev) / sizeof(OABBREV) - 1,
  1036.         sizeof(OABBREV), opts_abbcmp)) != NULL)
  1037.         return (optlist + ap->offset);
  1038.  
  1039.     /* Check list of options. */
  1040.     otmp.name = name;
  1041.     if ((op = bsearch(&otmp, optlist, sizeof(optlist) / sizeof(OPTLIST) - 1,
  1042.         sizeof(OPTLIST), opts_cmp)) != NULL)
  1043.         return (op);
  1044.         
  1045.     /*
  1046.      * Check to see if the name is the prefix of one (and only one)
  1047.      * option.  If so, return the option.
  1048.      */
  1049.     len = strlen(name);
  1050.     for (found = NULL, op = optlist; op->name != NULL; ++op) {
  1051.         if (op->name[0] < name[0])
  1052.             continue;
  1053.         if (op->name[0] > name[0])
  1054.             break;
  1055.         if (!memcmp(op->name, name, len)) {
  1056.             if (found != NULL)
  1057.                 return (NULL);
  1058.             found = op;
  1059.         }
  1060.     }
  1061.     return (found);
  1062. }
  1063.  
  1064. /* 
  1065.  * opts_nomatch --
  1066.  *    Standard nomatch error message for options.
  1067.  *
  1068.  * PUBLIC: void opts_nomatch __P((SCR *, char *));
  1069.  */
  1070. void
  1071. opts_nomatch(sp, name)
  1072.     SCR *sp;
  1073.     char *name;
  1074. {
  1075.     msgq_str(sp, M_ERR, name,
  1076.         "033|set: no %s option: 'set all' gives all option values");
  1077. }
  1078.  
  1079. static int
  1080. opts_abbcmp(a, b)
  1081.         const void *a, *b;
  1082. {
  1083.         return(strcmp(((OABBREV *)a)->name, ((OABBREV *)b)->name));
  1084. }
  1085.  
  1086. static int
  1087. opts_cmp(a, b)
  1088.         const void *a, *b;
  1089. {
  1090.         return(strcmp(((OPTLIST *)a)->name, ((OPTLIST *)b)->name));
  1091. }
  1092.  
  1093. /*
  1094.  * opts_copy --
  1095.  *    Copy a screen's OPTION array.
  1096.  *
  1097.  * PUBLIC: int opts_copy __P((SCR *, SCR *));
  1098.  */
  1099. int
  1100. opts_copy(orig, sp)
  1101.     SCR *orig, *sp;
  1102. {
  1103.     int cnt, rval;
  1104.  
  1105.     /* Copy most everything without change. */
  1106.     memcpy(sp->opts, orig->opts, sizeof(orig->opts));
  1107.  
  1108.     /* Copy the string edit options. */
  1109.     for (cnt = rval = 0; cnt < O_OPTIONCOUNT; ++cnt) {
  1110.         if (optlist[cnt].type != OPT_STR ||
  1111.             F_ISSET(&optlist[cnt], OPT_GLOBAL))
  1112.             continue;
  1113.         /*
  1114.          * If never set, or already failed, NULL out the entries --
  1115.          * have to continue after failure, otherwise would have two
  1116.          * screens referencing the same memory.
  1117.          */
  1118.         if (rval || O_STR(sp, cnt) == NULL) {
  1119.             o_set(sp, cnt, OS_NOFREE | OS_STR, NULL, 0);
  1120.             o_set(sp, cnt, OS_DEF | OS_NOFREE | OS_STR, NULL, 0);
  1121.             continue;
  1122.         }
  1123.  
  1124.         /* Copy the current string. */
  1125.         if (o_set(sp, cnt, OS_NOFREE | OS_STRDUP, O_STR(sp, cnt), 0)) {
  1126.             o_set(sp, cnt, OS_DEF | OS_NOFREE | OS_STR, NULL, 0);
  1127.             goto nomem;
  1128.         }
  1129.  
  1130.         /* Copy the default string. */
  1131.         if (O_D_STR(sp, cnt) != NULL && o_set(sp, cnt,
  1132.             OS_DEF | OS_NOFREE | OS_STRDUP, O_D_STR(sp, cnt), 0)) {
  1133. nomem:            msgq(orig, M_SYSERR, NULL);
  1134.             rval = 1;
  1135.         }
  1136.     }
  1137.     return (rval);
  1138. }
  1139.  
  1140. /*
  1141.  * opts_free --
  1142.  *    Free all option strings
  1143.  *
  1144.  * PUBLIC: void opts_free __P((SCR *));
  1145.  */
  1146. void
  1147. opts_free(sp)
  1148.     SCR *sp;
  1149. {
  1150.     int cnt;
  1151.  
  1152.     for (cnt = 0; cnt < O_OPTIONCOUNT; ++cnt) {
  1153.         if (optlist[cnt].type != OPT_STR ||
  1154.             F_ISSET(&optlist[cnt], OPT_GLOBAL))
  1155.             continue;
  1156.         if (O_STR(sp, cnt) != NULL)
  1157.             free(O_STR(sp, cnt));
  1158.         if (O_D_STR(sp, cnt) != NULL)
  1159.             free(O_D_STR(sp, cnt));
  1160.     }
  1161. }
  1162.