#include "config.h"
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <bitstring.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
#include "../vi/vi.h"
#include "pathnames.h"
static int opts_abbcmp(const void *, const void *);
static int opts_cmp(const void *, const void *);
static int opts_print(SCR *, OPTLIST const *);
OPTLIST const optlist[] = {
{"altwerase", f_altwerase, OPT_0BOOL, 0},
{"autoindent", NULL, OPT_0BOOL, 0},
{"autoprint", NULL, OPT_1BOOL, 0},
{"autowrite", NULL, OPT_0BOOL, 0},
{"backup", NULL, OPT_STR, 0},
{"beautify", NULL, OPT_0BOOL, 0},
{"cdpath", NULL, OPT_STR, 0},
{"cedit", NULL, OPT_STR, 0},
{"columns", f_columns, OPT_NUM, OPT_NOSAVE},
{"comment", NULL, OPT_0BOOL, 0},
{"edcompatible",NULL, OPT_0BOOL, 0},
{"escapetime", NULL, OPT_NUM, 0},
{"errorbells", NULL, OPT_0BOOL, 0},
{"expandtab", NULL, OPT_0BOOL, 0},
{"exrc", NULL, OPT_0BOOL, 0},
{"extended", f_recompile, OPT_0BOOL, 0},
{"filec", NULL, OPT_STR, 0},
{"flash", NULL, OPT_0BOOL, 0},
{"hardtabs", NULL, OPT_NUM, 0},
{"iclower", f_recompile, OPT_0BOOL, 0},
{"ignorecase", f_recompile, OPT_0BOOL, 0},
{"keytime", NULL, OPT_NUM, 0},
{"leftright", f_reformat, OPT_0BOOL, 0},
{"lines", f_lines, OPT_NUM, OPT_NOSAVE},
{"list", f_reformat, OPT_0BOOL, 0},
{"lock", NULL, OPT_1BOOL, 0},
{"magic", NULL, OPT_1BOOL, 0},
{"matchtime", NULL, OPT_NUM, 0},
{"mesg", NULL, OPT_1BOOL, 0},
{"noprint", f_print, OPT_STR, OPT_EARLYSET},
{"number", f_reformat, OPT_0BOOL, 0},
{"octal", f_print, OPT_0BOOL, OPT_EARLYSET},
{"open", NULL, OPT_1BOOL, 0},
{"paragraphs", f_paragraph, OPT_STR, 0},
{"path", NULL, OPT_STR, 0},
{"print", f_print, OPT_STR, OPT_EARLYSET},
{"prompt", NULL, OPT_1BOOL, 0},
{"readonly", f_readonly, OPT_0BOOL, OPT_ALWAYS},
{"recdir", NULL, OPT_STR, 0},
{"remap", NULL, OPT_1BOOL, 0},
{"report", NULL, OPT_NUM, 0},
{"ruler", NULL, OPT_0BOOL, 0},
{"scroll", NULL, OPT_NUM, 0},
{"searchincr", NULL, OPT_0BOOL, 0},
{"sections", f_section, OPT_STR, 0},
{"secure", f_secure, OPT_0BOOL, OPT_NOUNSET},
{"shell", NULL, OPT_STR, 0},
{"shellmeta", NULL, OPT_STR, 0},
{"shiftwidth", NULL, OPT_NUM, OPT_NOZERO},
{"showfilename",NULL, OPT_0BOOL, 0},
{"showmatch", NULL, OPT_0BOOL, 0},
{"showmode", NULL, OPT_0BOOL, 0},
{"sidescroll", NULL, OPT_NUM, OPT_NOZERO},
{"tabstop", f_reformat, OPT_NUM, OPT_NOZERO},
{"taglength", NULL, OPT_NUM, 0},
{"tags", NULL, OPT_STR, 0},
{"term", NULL, OPT_STR, OPT_ADISP|OPT_NOSAVE},
{"terse", NULL, OPT_0BOOL, 0},
{"tildeop", NULL, OPT_0BOOL, 0},
{"timeout", NULL, OPT_1BOOL, 0},
{"ttywerase", f_ttywerase, OPT_0BOOL, 0},
{"verbose", NULL, OPT_0BOOL, 0},
{"w1200", f_w1200, OPT_NUM, OPT_NDISP|OPT_NOSAVE},
{"w300", f_w300, OPT_NUM, OPT_NDISP|OPT_NOSAVE},
{"w9600", f_w9600, OPT_NUM, OPT_NDISP|OPT_NOSAVE},
{"warn", NULL, OPT_1BOOL, 0},
{"window", f_window, OPT_NUM, OPT_NOZERO},
{"windowname", NULL, OPT_0BOOL, 0},
{"wraplen", NULL, OPT_NUM, 0},
{"wrapmargin", NULL, OPT_NUM, 0},
{"wrapscan", NULL, OPT_1BOOL, 0},
{"writeany", NULL, OPT_0BOOL, 0},
{NULL},
};
typedef struct abbrev {
char *name;
int offset;
} OABBREV;
static OABBREV const abbrev[] = {
{"ai", O_AUTOINDENT},
{"ap", O_AUTOPRINT},
{"aw", O_AUTOWRITE},
{"bf", O_BEAUTIFY},
{"co", O_COLUMNS},
{"eb", O_ERRORBELLS},
{"ed", O_EDCOMPATIBLE},
{"et", O_EXPANDTAB},
{"ex", O_EXRC},
{"ht", O_HARDTABS},
{"ic", O_IGNORECASE},
{"li", O_LINES},
{"nu", O_NUMBER},
{"para", O_PARAGRAPHS},
{"ro", O_READONLY},
{"scr", O_SCROLL},
{"sect", O_SECTIONS},
{"sh", O_SHELL},
{"sm", O_SHOWMATCH},
{"smd", O_SHOWMODE},
{"sw", O_SHIFTWIDTH},
{"tag", O_TAGS},
{"tl", O_TAGLENGTH},
{"to", O_TIMEOUT},
{"ts", O_TABSTOP},
{"tty", O_TERM},
{"ttytype", O_TERM},
{"w", O_WINDOW},
{"wa", O_WRITEANY},
{"wi", O_WINDOW},
{"wl", O_WRAPLEN},
{"wm", O_WRAPMARGIN},
{"ws", O_WRAPSCAN},
{NULL},
};
int
opts_init(SCR *sp, int *oargs)
{
ARGS *argv[2], a, b;
OPTLIST const *op;
u_long v;
int optindx;
char *s, b1[1024];
a.bp = b1;
b.bp = NULL;
a.len = b.len = 0;
argv[0] = &a;
argv[1] = &b;
#define OI_b1(indx) { \
a.len = strlen(b1); \
if (opts_set(sp, argv, NULL)) { \
optindx = indx; \
goto err; \
} \
}
#define OI(indx, str) { \
(void)strlcpy(b1, (str), sizeof(b1)); \
OI_b1(indx); \
}
if (o_set(sp, O_TERM, 0, NULL, GO_TERM)) {
optindx = O_TERM;
goto err;
}
F_SET(&sp->opts[O_TERM], OPT_GLOBAL);
if (o_set(sp, O_LINES, 0, NULL, GO_LINES)) {
optindx = O_LINES;
goto err;
}
F_SET(&sp->opts[O_LINES], OPT_GLOBAL);
if (o_set(sp, O_COLUMNS, 0, NULL, GO_COLUMNS)) {
optindx = O_COLUMNS;
goto err;
}
F_SET(&sp->opts[O_COLUMNS], OPT_GLOBAL);
if (o_set(sp, O_SECURE, 0, NULL, GO_SECURE)) {
optindx = O_SECURE;
goto err;
}
F_SET(&sp->opts[O_SECURE], OPT_GLOBAL);
(void)snprintf(b1, sizeof(b1),
"cdpath=%s", (s = getenv("CDPATH")) == NULL ? ":" : s);
OI_b1(O_CDPATH);
OI(O_ESCAPETIME, "escapetime=1");
OI(O_FILEC, "filec=\t");
OI(O_KEYTIME, "keytime=6");
OI(O_MATCHTIME, "matchtime=7");
OI(O_REPORT, "report=5");
OI(O_PARAGRAPHS, "paragraphs=IPLPPPQPP LIpplpipbpBlBdPpLpIt");
OI(O_PATH, "path=");
(void)snprintf(b1, sizeof(b1), "recdir=%s", _PATH_PRESERVE);
OI_b1(O_RECDIR);
OI(O_SECTIONS, "sections=NHSHH HUnhshShSs");
(void)snprintf(b1, sizeof(b1),
"shell=%s", (s = getenv("SHELL")) == NULL ? _PATH_BSHELL : s);
OI_b1(O_SHELL);
OI(O_SHELLMETA, "shellmeta=~{[*?$`'\"\\");
OI(O_SHIFTWIDTH, "shiftwidth=8");
OI(O_SIDESCROLL, "sidescroll=16");
OI(O_TABSTOP, "tabstop=8");
(void)snprintf(b1, sizeof(b1), "tags=%s", _PATH_TAGS);
OI_b1(O_TAGS);
if ((v = (O_VAL(sp, O_LINES) - 1) / 2) == 0)
v = 1;
(void)snprintf(b1, sizeof(b1), "scroll=%ld", v);
OI_b1(O_SCROLL);
if (sp->gp->scr_baud(sp, &v))
return (1);
if (v <= 600)
v = 8;
else if (v <= 1200)
v = 16;
else
v = O_VAL(sp, O_LINES) - 1;
(void)snprintf(b1, sizeof(b1), "window=%lu", v);
OI_b1(O_WINDOW);
for (op = optlist, optindx = 0; op->name != NULL; ++op, ++optindx)
switch (op->type) {
case OPT_0BOOL:
break;
case OPT_1BOOL:
O_SET(sp, optindx);
O_D_SET(sp, optindx);
break;
case OPT_NUM:
o_set(sp, optindx, OS_DEF, NULL, O_VAL(sp, optindx));
break;
case OPT_STR:
if (O_STR(sp, optindx) != NULL && o_set(sp, optindx,
OS_DEF | OS_NOFREE | OS_STRDUP, O_STR(sp, optindx), 0))
goto err;
break;
default:
abort();
}
for (; *oargs != -1; ++oargs)
OI(*oargs, optlist[*oargs].name);
return (0);
#undef OI
#undef OI_b1
err: msgq(sp, M_ERR,
"Unable to set default %s option", optlist[optindx].name);
return (1);
}
int
opts_set(SCR *sp, ARGS *argv[], char *usage)
{
enum optdisp disp;
enum nresult nret;
OPTLIST const *op;
OPTION *spo;
u_long value, turnoff;
int ch, equals, nf, nf2, offset, qmark, rval;
char *endp, *name, *p, *sep, *t;
disp = NO_DISPLAY;
for (rval = 0; argv[0]->len != 0; ++argv) {
if (!strcmp(argv[0]->bp, "all")) {
disp = ALL_DISPLAY;
continue;
}
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,
"Usage: %s", usage);
return (1);
}
sep = p;
if (ch == '=')
equals = 1;
else
qmark = 1;
break;
}
turnoff = 0;
op = NULL;
if (sep != NULL)
*sep++ = '\0';
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;
}
offset = op - optlist;
spo = sp->opts + offset;
if (!equals && !qmark &&
argv[1]->len == 1 && argv[1]->bp[0] == '?') {
++argv;
qmark = 1;
}
switch (op->type) {
case OPT_0BOOL:
case OPT_1BOOL:
if (F_ISSET(op, OPT_NOUNSET) && turnoff) {
msgq_str(sp, M_ERR, name,
"set: the %s option may not be turned off");
rval = 1;
break;
}
if (equals) {
msgq_str(sp, M_ERR, name,
"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;
}
if (!F_ISSET(op, OPT_ALWAYS)) {
if (turnoff) {
if (!O_ISSET(sp, offset))
break;
} else {
if (O_ISSET(sp, offset))
break;
}
}
if (F_ISSET(op, OPT_EARLYSET)) {
if (turnoff)
O_CLR(sp, offset);
else
O_SET(sp, offset);
}
if ((op->func != NULL &&
op->func(sp, spo, NULL, &turnoff)) ||
ex_optchange(sp, offset, NULL, &turnoff) ||
v_optchange(sp, offset, NULL, &turnoff) ||
sp->gp->scr_optchange(sp, offset, NULL, &turnoff)) {
rval = 1;
break;
}
if (!F_ISSET(op, OPT_EARLYSET)) {
if (turnoff)
O_CLR(sp, offset);
else
O_SET(sp, offset);
}
break;
case OPT_NUM:
if (turnoff) {
msgq_str(sp, M_ERR, name,
"set: %s option isn't a boolean");
rval = 1;
break;
}
if (qmark || !equals) {
if (!disp)
disp = SELECT_DISPLAY;
F_SET(spo, OPT_SELECTED);
break;
}
if (!isdigit(sep[0]))
goto badnum;
if ((nret =
nget_uslong(&value, sep, &endp, 10)) != NUM_OK) {
p = msg_print(sp, name, &nf);
t = msg_print(sp, sep, &nf2);
switch (nret) {
case NUM_ERR:
msgq(sp, M_SYSERR,
"set: %s option: %s", p, t);
break;
case NUM_OVER:
msgq(sp, M_ERR,
"set: %s option: %s: value overflow", p, t);
break;
case NUM_OK:
case NUM_UNDER:
abort();
}
if (nf)
FREE_SPACE(sp, p, 0);
if (nf2)
FREE_SPACE(sp, t, 0);
rval = 1;
break;
}
if (*endp && !isblank(*endp)) {
badnum: p = msg_print(sp, name, &nf);
t = msg_print(sp, sep, &nf2);
msgq(sp, M_ERR,
"set: %s option: %s is an illegal number", p, t);
if (nf)
FREE_SPACE(sp, p, 0);
if (nf2)
FREE_SPACE(sp, t, 0);
rval = 1;
break;
}
if (F_ISSET(op, OPT_NOZERO) && value == 0) {
msgq_str(sp, M_ERR, name,
"set: the %s option may never be set to 0");
rval = 1;
break;
}
if (!F_ISSET(op, OPT_ALWAYS) &&
O_VAL(sp, offset) == value)
break;
if (F_ISSET(op, OPT_EARLYSET)) {
if (o_set(sp, offset, 0, NULL, value)) {
rval = 1;
break;
}
}
if ((op->func != NULL &&
op->func(sp, spo, sep, &value)) ||
ex_optchange(sp, offset, sep, &value) ||
v_optchange(sp, offset, sep, &value) ||
sp->gp->scr_optchange(sp, offset, sep, &value)) {
rval = 1;
break;
}
if (!F_ISSET(op, OPT_EARLYSET)) {
if (o_set(sp, offset, 0, NULL, value))
rval = 1;
}
break;
case OPT_STR:
if (turnoff) {
msgq_str(sp, M_ERR, name,
"set: %s option isn't a boolean");
rval = 1;
break;
}
if (qmark || !equals) {
if (!disp)
disp = SELECT_DISPLAY;
F_SET(spo, OPT_SELECTED);
break;
}
if (!F_ISSET(op, OPT_ALWAYS) &&
O_STR(sp, offset) != NULL &&
!strcmp(O_STR(sp, offset), sep))
break;
if (F_ISSET(op, OPT_EARLYSET)) {
if (o_set(sp, offset, OS_STRDUP, sep, 0)) {
rval = 1;
break;
}
}
if ((op->func != NULL &&
op->func(sp, spo, sep, NULL)) ||
ex_optchange(sp, offset, sep, NULL) ||
v_optchange(sp, offset, sep, NULL) ||
sp->gp->scr_optchange(sp, offset, sep, NULL)) {
rval = 1;
break;
}
if (!F_ISSET(op, OPT_EARLYSET)) {
if (o_set(sp, offset, OS_STRDUP, sep, 0))
rval = 1;
}
break;
default:
abort();
}
}
if (disp != NO_DISPLAY)
opts_dump(sp, disp);
return (rval);
}
int
o_set(SCR *sp, int opt, u_int flags, char *str, u_long val)
{
OPTION *op;
op = F_ISSET(&sp->opts[opt], OPT_GLOBAL) ?
&sp->gp->opts[sp->opts[opt].o_cur.val] : &sp->opts[opt];
if (LF_ISSET(OS_STRDUP) && (str = strdup(str)) == NULL) {
msgq(sp, M_SYSERR, NULL);
return (1);
}
if (LF_ISSET(OS_DEF))
if (LF_ISSET(OS_STR | OS_STRDUP)) {
if (!LF_ISSET(OS_NOFREE) && op->o_def.str != NULL)
free(op->o_def.str);
op->o_def.str = str;
} else
op->o_def.val = val;
else
if (LF_ISSET(OS_STR | OS_STRDUP)) {
if (!LF_ISSET(OS_NOFREE) && op->o_cur.str != NULL)
free(op->o_cur.str);
op->o_cur.str = str;
} else
op->o_cur.val = val;
return (0);
}
int
opts_empty(SCR *sp, int off, int silent)
{
char *p;
if ((p = O_STR(sp, off)) == NULL || p[0] == '\0') {
if (!silent)
msgq_str(sp, M_ERR, optlist[off].name,
"No %s edit option specified");
return (1);
}
return (0);
}
void
opts_dump(SCR *sp, enum optdisp type)
{
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];
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;
}
for (b_num = s_num = 0, op = optlist; op->name != NULL; ++op) {
cnt = op - optlist;
if (F_ISSET(op, OPT_NDISP))
continue;
switch (type) {
case ALL_DISPLAY:
break;
case CHANGED_DISPLAY:
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) ||
(O_D_STR(sp, cnt) != NULL &&
!strcmp(O_STR(sp, cnt), O_D_STR(sp, cnt))))
continue;
break;
}
break;
case SELECT_DISPLAY:
if (!F_ISSET(&sp->opts[cnt], OPT_SELECTED))
continue;
break;
default:
case NO_DISPLAY:
abort();
}
F_CLR(&sp->opts[cnt], OPT_SELECTED);
curlen = strlen(op->name);
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;
}
if (curlen <= colwidth - 2)
s_op[s_num++] = cnt;
else
b_op[b_num++] = cnt;
}
if (s_num > 0) {
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]]);
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");
}
static int
opts_print(SCR *sp, OPTLIST const *op)
{
int curlen, offset;
curlen = 0;
offset = op - optlist;
switch (op->type) {
case OPT_0BOOL:
case OPT_1BOOL:
curlen += ex_printf(sp,
"%s%s", O_ISSET(sp, offset) ? "" : "no", op->name);
break;
case OPT_NUM:
curlen += ex_printf(sp, "%s=%ld", op->name, O_VAL(sp, offset));
break;
case OPT_STR:
curlen += ex_printf(sp, "%s=\"%s\"", op->name,
O_STR(sp, offset) == NULL ? "" : O_STR(sp, offset));
break;
}
return (curlen);
}
int
opts_save(SCR *sp, FILE *fp)
{
OPTLIST const *op;
int ch, cnt;
char *p;
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))
(void)fprintf(fp, "set %s\n", op->name);
else
(void)fprintf(fp, "set no%s\n", op->name);
break;
case OPT_NUM:
(void)fprintf(fp,
"set %s=%-3ld\n", op->name, O_VAL(sp, cnt));
break;
case OPT_STR:
if (O_STR(sp, cnt) == NULL)
break;
(void)fprintf(fp, "set ");
for (p = op->name; (ch = *p) != '\0'; ++p) {
if (isblank(ch) || ch == '\\')
(void)putc('\\', fp);
(void)putc(ch, fp);
}
(void)putc('=', fp);
for (p = O_STR(sp, cnt); (ch = *p) != '\0'; ++p) {
if (isblank(ch) || ch == '\\')
(void)putc('\\', fp);
(void)putc(ch, fp);
}
(void)putc('\n', fp);
break;
}
if (ferror(fp)) {
msgq(sp, M_SYSERR, NULL);
return (1);
}
}
return (0);
}
OPTLIST const *
opts_search(char *name)
{
OPTLIST const *op, *found;
OABBREV atmp, *ap;
OPTLIST otmp;
size_t len;
atmp.name = name;
if ((ap = bsearch(&atmp, abbrev, sizeof(abbrev) / sizeof(OABBREV) - 1,
sizeof(OABBREV), opts_abbcmp)) != NULL)
return (optlist + ap->offset);
otmp.name = name;
if ((op = bsearch(&otmp, optlist, sizeof(optlist) / sizeof(OPTLIST) - 1,
sizeof(OPTLIST), opts_cmp)) != NULL)
return (op);
len = strlen(name);
for (found = NULL, op = optlist; op->name != NULL; ++op) {
if (op->name[0] < name[0])
continue;
if (op->name[0] > name[0])
break;
if (!memcmp(op->name, name, len)) {
if (found != NULL)
return (NULL);
found = op;
}
}
return (found);
}
void
opts_nomatch(SCR *sp, char *name)
{
msgq_str(sp, M_ERR, name,
"set: no %s option: 'set all' gives all option values");
}
static int
opts_abbcmp(const void *a, const void *b)
{
return(strcmp(((OABBREV *)a)->name, ((OABBREV *)b)->name));
}
static int
opts_cmp(const void *a, const void *b)
{
return(strcmp(((OPTLIST *)a)->name, ((OPTLIST *)b)->name));
}
int
opts_copy(SCR *orig, SCR *sp)
{
int cnt, rval;
memcpy(sp->opts, orig->opts, sizeof(orig->opts));
for (cnt = rval = 0; cnt < O_OPTIONCOUNT; ++cnt) {
if (optlist[cnt].type != OPT_STR ||
F_ISSET(&optlist[cnt], OPT_GLOBAL))
continue;
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;
}
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;
}
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);
}
void
opts_free(SCR *sp)
{
int cnt;
for (cnt = 0; cnt < O_OPTIONCOUNT; ++cnt) {
if (optlist[cnt].type != OPT_STR ||
F_ISSET(&optlist[cnt], OPT_GLOBAL))
continue;
free(O_STR(sp, cnt));
free(O_D_STR(sp, cnt));
}
}