/* This file contains the code that manages the run-time options -- The
* values that can be modified via the "set" command.
/* maximum width to permit for strings, including ="" */
/* These are the default values of all options */
char o_autoindent
[1] = {FALSE
};
char o_autoprint
[1] = {TRUE
};
char o_autotab
[1] = {TRUE
};
char o_autowrite
[1] = {FALSE
};
char o_columns
[3] = {80, 32, ~0};
char o_directory
[30] = TMPDIR
;
char o_edcompatible
[1] = {FALSE
};
char o_equalprg
[80] = {"fmt"};
char o_errorbells
[1] = {TRUE
};
char o_exrefresh
[1] = {TRUE
};
char o_ignorecase
[1] = {FALSE
};
char o_keytime
[3] = {2, 0, 50};
char o_keywordprg
[80] = {KEYWORDPRG
};
char o_lines
[3] = {25, 2, 96};
char o_list
[1] = {FALSE
};
char o_number
[1] = {FALSE
};
char o_readonly
[1] = {FALSE
};
char o_remap
[1] = {TRUE
};
char o_report
[3] = {5, 1, 127};
char o_scroll
[3] = {12, 1, 127};
char o_shell
[60] = SHELL
;
char o_shiftwidth
[3] = {8, 1, ~0};
char o_sidescroll
[3] = {8, 1, 40};
char o_sync
[1] = {NEEDSYNC
};
char o_tabstop
[3] = {8, 1, 40};
char o_flash
[1] = {TRUE
};
char o_wrapscan
[1] = {TRUE
};
char o_beautify
[1] = {FALSE
};
char o_exrc
[1] = {FALSE
};
char o_nearscroll
[3] = {15, 0, ~0};
char o_novice
[1] = {FALSE
};
char o_prompt
[1] = {TRUE
};
char o_taglength
[3] = {0, 0, 30};
char o_tags
[256] = {"tags"};
char o_terse
[1] = {FALSE
};
char o_window
[3] = {0, 1, 24};
char o_wrapmargin
[3] = {0, 0, ~0};
char o_writeany
[1] = {FALSE
};
char o_cc
[30] = {CC_COMMAND
};
char o_make
[30] = {MAKE_COMMAND
};
char o_charattr
[1] = {FALSE
};
char o_digraph
[1] = {FALSE
};
= {"\207\200\201\232\202\220\204\216\206\217\221\222\224\231\244\245"}
/* initialized by initopts() */
char o_hideformat
[1] = {FALSE
};
char o_inputmode
[1] = {FALSE
};
char o_ruler
[1] = {FALSE
};
char o_magic
[1] = {TRUE
};
char o_modelines
[1] = {FALSE
};
char o_paragraphs
[30] = "PPppIPLPQP";
char o_sections
[30] = "NHSHSSSEse";
char o_pcbios
[1] = {TRUE
};
char o_showmatch
[1] = {FALSE
};
char o_tagstack
[1] = {TRUE
};
/* The following describes the names & types of all options */
#define SET 0x01 /* this option has had its value altered */
#define CANSET 0x02 /* this option can be set at any time */
#define RCSET 0x06 /* this option can be set in a .exrc file only */
#define NOSAVE 0x0a /* this option should never be saved by mkexrc */
#define WSET 0x20 /* is this the "window" size option? */
#define MR 0x40 /* does this option affect the way text is displayed? */
char *name
; /* name of an option */
char *nm
; /* short name of an option */
char type
; /* type of an option */
char flags
; /* boolean: has this option been set? */
/* name type flags value */
{ "autoindent", "ai", BOOL
, CANSET
, o_autoindent
},
{ "autoprint", "ap", BOOL
, CANSET
, o_autoprint
},
{ "autotab", "at", BOOL
, CANSET
, o_autotab
},
{ "autowrite", "aw", BOOL
, CANSET
, o_autowrite
},
{ "beautify", "bf", BOOL
, CANSET
, o_beautify
},
{ "cc", "cc", STR
, CANSET
, o_cc
},
{ "charattr", "ca", BOOL
, CANSET
|MR
, o_charattr
},
{ "columns", "co", NUM
, SET
|NOSAVE
|MR
, o_columns
},
{ "digraph", "dig", BOOL
, CANSET
, o_digraph
},
{ "directory", "dir", STR
, RCSET
, o_directory
},
{ "edcompatible","ed", BOOL
, CANSET
, o_edcompatible
},
{ "equalprg", "ep", STR
, CANSET
, o_equalprg
},
{ "errorbells", "eb", BOOL
, CANSET
, o_errorbells
},
{ "exrc", "exrc", BOOL
, CANSET
, o_exrc
},
{ "exrefresh", "er", BOOL
, CANSET
, o_exrefresh
},
{ "flash", "vbell",BOOL
, CANSET
, o_flash
},
{ "flipcase", "fc", STR
, CANSET
, o_flipcase
},
{ "hideformat", "hf", BOOL
, CANSET
|MR
, o_hideformat
},
{ "ignorecase", "ic", BOOL
, CANSET
, o_ignorecase
},
{ "inputmode", "im", BOOL
, CANSET
, o_inputmode
},
{ "keytime", "kt", NUM
, CANSET
, o_keytime
},
{ "keywordprg", "kp", STR
, CANSET
, o_keywordprg
},
{ "lines", "ls", NUM
, SET
|NOSAVE
|MR
, o_lines
},
{ "list", "li", BOOL
, CANSET
|MR
, o_list
},
{ "magic", "ma", BOOL
, CANSET
, o_magic
},
{ "make", "mk", STR
, CANSET
, o_make
},
{ "mesg", "me", BOOL
, CANSET
, o_mesg
},
{ "modelines", "ml", BOOL
, CANSET
, o_modelines
},
{ "more", "mo", BOOL
, CANSET
, o_more
},
{ "nearscroll", "ns", NUM
, CANSET
, o_nearscroll
},
{ "novice", "nov", BOOL
, CANSET
, o_novice
},
{ "number", "nu", BOOL
, CANSET
|MR
, o_number
},
{ "paragraphs", "para", STR
, CANSET
, o_paragraphs
},
{ "pcbios", "pc", BOOL
, SET
|NOSAVE
, o_pcbios
},
{ "prompt", "pr", BOOL
, CANSET
, o_prompt
},
{ "readonly", "ro", BOOL
, CANSET
, o_readonly
},
{ "remap", "remap",BOOL
, CANSET
, o_remap
},
{ "report", "re", NUM
, CANSET
, o_report
},
{ "ruler", "ru", BOOL
, CANSET
, o_ruler
},
{ "scroll", "sc", NUM
, CANSET
, o_scroll
},
{ "sections", "sect", STR
, CANSET
, o_sections
},
{ "shell", "sh", STR
, CANSET
, o_shell
},
{ "showmatch", "sm", BOOL
, CANSET
, o_showmatch
},
{ "showmode", "smd", BOOL
, CANSET
, o_smd
},
{ "shiftwidth", "sw", NUM
, CANSET
, o_shiftwidth
},
{ "sidescroll", "ss", NUM
, CANSET
, o_sidescroll
},
{ "sync", "sy", BOOL
, CANSET
, o_sync
},
{ "tabstop", "ts", NUM
, CANSET
|MR
, o_tabstop
},
{ "taglength", "tl", NUM
, CANSET
, o_taglength
},
{ "tags", "tag", STR
, CANSET
, o_tags
},
{ "tagstack", "tgs", BOOL
, CANSET
, o_tagstack
},
{ "term", "te", STR
, SET
, o_term
},
{ "terse", "tr", BOOL
, CANSET
, o_terse
},
{ "timeout", "to", BOOL
, CANSET
, o_keytime
},
{ "window", "wi", NUM
, CANSET
|MR
|WSET
, o_window
},
{ "wrapmargin", "wm", NUM
, CANSET
, o_wrapmargin
},
{ "wrapscan", "ws", BOOL
, CANSET
, o_wrapscan
},
{ "writeany", "wr", BOOL
, CANSET
, o_writeany
},
{ NULL
, NULL
, 0, CANSET
, NULL
}
/* This function initializes certain options from environment variables, etc. */
/* set some stuff from environment variables */
if (val
= getenv("COMSPEC")) /* yes, ASSIGNMENT! */
if (val
= getenv("SHELL")) /* yes, ASSIGNMENT! */
strcpy(o_term
, termtype
);
if (strcmp(termtype
, "pcbios"))
#if AMIGA || MSDOS || TOS
if ((val
= getenv("TMP")) /* yes, ASSIGNMENT! */
|| (val
= getenv("TEMP")))
strcpy(o_directory
, val
);
if ((val
= getenv("LINES")) && atoi(val
) > 4) /* yes, ASSIGNMENT! */
if ((val
= getenv("COLUMNS")) && atoi(val
) > 30) /* yes, ASSIGNMENT! */
*o_scroll
= LINES
/ 2 - 1;
o_window
[0] = o_window
[2] = *o_lines
;
*o_nearscroll
= *o_lines
;
/* disable the flash option if we don't know how to do a flash */
for (i
= 0; opts
[i
].value
!= o_flash
; i
++)
opts
[i
].flags
&= ~CANSET
;
for (i
= 0, val
= o_flipcase
; i
< 32; i
++)
/* leave out the multiply/divide symbols */
/* add lower/uppercase pair */
/* initialize the ctype package */
#endif /* not NO_DIGRAPH */
/* This function lists the current values of all options */
int all
; /* boolean: dump all options, or just set ones? */
char nbuf
[4]; /* used for converting numbers to ASCII */
int widths
[5]; /* width of each column, including gap */
int ncols
; /* number of columns */
int nrows
; /* number of options per column */
int nset
; /* number of options to be output */
int width
; /* width of a particular option */
int todump
[60]; /* indicies of options to be dumped */
/* step 1: count the number of set options */
for (nset
= i
= 0; opts
[i
].name
; i
++)
if (all
|| (opts
[i
].flags
& SET
))
/* step two: try to use as many columns as possible */
for (ncols
= (nset
> 5 ? 5 : nset
); ncols
> 1; ncols
--)
/* how many would go in this column? */
nrows
= (nset
+ ncols
- 1) / ncols
;
/* figure out the width of each column */
for (i
= 0; i
< ncols
; i
++)
for (j
= 0, k
= nrows
* i
; j
< nrows
&& k
< nset
; j
++, k
++)
/* figure out the width of a particular option */
switch (opts
[todump
[k
]].type
)
if (!*opts
[todump
[k
]].value
)
width
= 3 + strlen(opts
[todump
[k
]].value
);
width
+= strlen(opts
[todump
[k
]].name
);
/* if this is the widest so far, widen col */
/* if the total width is narrow enough, then use it */
for (width
= -2, i
= 0; i
< ncols
; i
++)
/* step 3: output the columns */
nrows
= (nset
+ ncols
- 1) / ncols
;
for (i
= 0; i
< nrows
; i
++)
for (j
= 0; j
< ncols
; j
++)
/* if we hit the end of the options, quit */
/* output this option's value */
switch (opts
[todump
[k
]].type
)
if (!*opts
[todump
[k
]].value
)
qaddstr(opts
[todump
[k
]].name
);
width
+= strlen(opts
[todump
[k
]].name
);
sprintf(nbuf
, "%-3d", UCHAR(*opts
[todump
[k
]].value
));
qaddstr(opts
[todump
[k
]].name
);
width
= 4 + strlen(opts
[todump
[k
]].name
);
qaddstr(opts
[todump
[k
]].name
);
strcpy(tmpblk
.c
, opts
[todump
[k
]].value
);
width
= 3 + strlen(tmpblk
.c
);
strcpy(tmpblk
.c
+ MAXWIDTH
- 6, "...");
width
+= strlen(opts
[todump
[k
]].name
);
/* pad the field to the correct size */
while (width
< widths
[j
] + 2)
for (i
= col
= 0; opts
[i
].name
; i
++)
/* if not set and not all, ignore this option */
if (!all
&& !(opts
[i
].flags
& SET
))
/* align this option in one of the columns */
col
+= strlen(opts
[i
].name
);
sprintf(nbuf
, "%-3d", UCHAR(*opts
[i
].value
));
col
+= 4 + strlen(opts
[i
].name
);
col
+= 3 + strlen(opts
[i
].name
) + strlen(opts
[i
].value
);
/* This function saves the current configuration of options to a file */
int fd
; /* file descriptor to write to */
/* write each set options */
for (i
= 0; opts
[i
].name
; i
++)
/* if unset or unsettable, ignore this option */
if ((opts
[i
].flags
& (SET
|CANSET
|NOSAVE
)) != (SET
|CANSET
))
strcpy(pos
, opts
[i
].name
);
sprintf(pos
, "%s=%-3d\n", opts
[i
].name
, *opts
[i
].value
& 0xff);
sprintf(pos
, "%s=\"%s\"\n", opts
[i
].name
, opts
[i
].value
);
twrite(fd
, buf
, (unsigned)strlen(buf
));
/* This function changes the values of one or more options. */
void setopts(assignments
)
char *assignments
; /* a string containing option assignments */
char *name
; /* name of variable in assignments */
char *value
; /* value of the variable */
char *scan
; /* used for moving through strings */
char *build
; /* used for copying chars from "scan" */
char *prefix
; /* pointer to "neg" or "no" at front of a boolean */
int quote
; /* boolean: inside '"' quotes? */
/* reset the upper limit of "window" option to lines-1 */
*o_window
= *o_lines
- 1;
/* for each assignment... */
for (name
= assignments
; *name
; )
if (*name
== ' ' || *name
== '\t')
/* after the name, find the value (if any) */
for (scan
= name
; isalnum(*scan
); scan
++)
for (quote
= FALSE
; *scan
&& (quote
|| !isspace(*scan
)); scan
++)
else if (*scan
== '\\' && scan
[1])
else /* no "=" so it is probably boolean... */
if (!strcmp(name
, "novice"))
/* don't check for a "no" prefix */;
if (prefix
[0] == 'n' && prefix
[1] == 'o')
else if (prefix
[0] == 'n' && prefix
[1] == 'e' && prefix
[2] == 'g')
opts
[i
].name
&& strcmp(opts
[i
].name
, name
) && strcmp(opts
[i
].nm
, name
);
/* change the variable */
/* only complain about unknown options if we're editing
* a file; i.e., if we're not executing the .exrc now.
msg("invalid option name \"%s\"", name
);
else if ((opts
[i
].flags
& CANSET
) != CANSET
)
msg("option \"%s\" can't be altered", name
);
else if ((opts
[i
].flags
& RCSET
) != CANSET
&& nlines
>= 1L)
msg("option \"%s\" can only be set in a %s file", name
, EXRC
);
msg("option \"[no]%s\" is boolean", name
);
if (j
== 0 && *value
!= '0')
msg("option \"%s\" must have a numeric value", name
);
else if (j
< opts
[i
].value
[1] || j
> (opts
[i
].value
[2] & 0xff))
msg("option \"%s\" must have a value between %d and %d",
name
, opts
[i
].value
[1], opts
[i
].value
[2] & 0xff);
*opts
[i
].value
= atoi(value
);
strcpy(opts
[i
].value
, value
);
redraw(MARK_UNSET
, FALSE
);
if (opts
[i
].flags
& WSET
)
else /* valid option, no value */
if (opts
[i
].type
== BOOL
)
else if (prefix
[1] == 'o')
*opts
[i
].value
= !*opts
[i
].value
;
redraw(MARK_UNSET
, FALSE
);
msg("option \"%s\" must be given a value", name
);
/* move on to the next option */
/* special processing ... */
/* if "novice" is set, then ":set report=1 showmode nomagic" */
/* if "readonly" then set the READONLY flag for this file */
/* re-initialize the ctype package */
#endif /* not NO_DIGRAPH */
/* copy o_lines and o_columns into LINES and COLS */
LINES
= (*o_lines
& 255);
COLS
= (*o_columns
& 255);