NetBSD/usr.bin/vi/common/options_f.c

368 lines
6.6 KiB
C
Raw Normal View History

1994-08-17 20:17:19 +04:00
/*-
* Copyright (c) 1993, 1994
* The Regents of the University of California. All rights reserved.
1996-05-20 06:01:36 +04:00
* Copyright (c) 1993, 1994, 1995, 1996
* Keith Bostic. All rights reserved.
1994-08-17 20:17:19 +04:00
*
1996-05-20 06:01:36 +04:00
* See the LICENSE file for redistribution information.
1994-08-17 20:17:19 +04:00
*/
1996-05-20 06:01:36 +04:00
#include "config.h"
1994-08-17 20:17:19 +04:00
#ifndef lint
1996-05-20 06:01:36 +04:00
static const char sccsid[] = "@(#)options_f.c 10.23 (Berkeley) 5/4/96";
1994-08-17 20:17:19 +04:00
#endif /* not lint */
#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>
#include <unistd.h>
1996-05-20 06:01:36 +04:00
#include "common.h"
1994-08-17 20:17:19 +04:00
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_altwerase __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_altwerase(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
if (!*valp)
1994-08-17 20:17:19 +04:00
O_CLR(sp, O_TTYWERASE);
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_columns __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_columns(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
/* Validate the number. */
1996-05-20 06:01:36 +04:00
if (*valp < MINIMUM_SCREEN_COLS) {
msgq(sp, M_ERR, "040|Screen columns too small, less than %d",
1994-08-17 20:17:19 +04:00
MINIMUM_SCREEN_COLS);
return (1);
}
1996-05-20 06:01:36 +04:00
/*
* !!!
* It's not uncommon for allocation of huge chunks of memory to cause
* core dumps on various systems. So, we prune out numbers that are
* "obviously" wrong. Vi will not work correctly if it has the wrong
* number of lines/columns for the screen, but at least we don't drop
* core.
*/
#define MAXIMUM_SCREEN_COLS 500
if (*valp > MAXIMUM_SCREEN_COLS) {
msgq(sp, M_ERR, "041|Screen columns too large, greater than %d",
MAXIMUM_SCREEN_COLS);
return (1);
}
1994-08-17 20:17:19 +04:00
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_lines __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_lines(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
/* Validate the number. */
1996-05-20 06:01:36 +04:00
if (*valp < MINIMUM_SCREEN_ROWS) {
msgq(sp, M_ERR, "042|Screen lines too small, less than %d",
1994-08-17 20:17:19 +04:00
MINIMUM_SCREEN_ROWS);
return (1);
}
/*
1996-05-20 06:01:36 +04:00
* !!!
* It's not uncommon for allocation of huge chunks of memory to cause
* core dumps on various systems. So, we prune out numbers that are
* "obviously" wrong. Vi will not work correctly if it has the wrong
* number of lines/columns for the screen, but at least we don't drop
* core.
1994-08-17 20:17:19 +04:00
*/
1996-05-20 06:01:36 +04:00
#define MAXIMUM_SCREEN_ROWS 500
if (*valp > MAXIMUM_SCREEN_ROWS) {
msgq(sp, M_ERR, "043|Screen lines too large, greater than %d",
MAXIMUM_SCREEN_ROWS);
1994-08-17 20:17:19 +04:00
return (1);
}
1996-05-20 06:01:36 +04:00
/*
* Set the value, and the related scroll value. If no window
* value set, set a new default window.
*/
o_set(sp, O_LINES, 0, NULL, *valp);
if (*valp == 1) {
sp->defscroll = 1;
if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
O_VAL(sp, O_WINDOW) > *valp) {
o_set(sp, O_WINDOW, 0, NULL, 1);
o_set(sp, O_WINDOW, OS_DEF, NULL, 1);
1994-08-17 20:17:19 +04:00
}
} else {
1996-05-20 06:01:36 +04:00
sp->defscroll = (*valp - 1) / 2;
if (O_VAL(sp, O_WINDOW) == O_D_VAL(sp, O_WINDOW) ||
O_VAL(sp, O_WINDOW) > *valp) {
o_set(sp, O_WINDOW, 0, NULL, *valp - 1);
o_set(sp, O_WINDOW, OS_DEF, NULL, *valp - 1);
1994-08-17 20:17:19 +04:00
}
}
return (0);
}
/*
1996-05-20 06:01:36 +04:00
* PUBLIC: int f_lisp __P((SCR *, OPTION *, char *, u_long *));
1994-08-17 20:17:19 +04:00
*/
1996-05-20 06:01:36 +04:00
int
f_lisp(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
msgq(sp, M_ERR, "044|The lisp option is not implemented");
1994-08-17 20:17:19 +04:00
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_msgcat __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_msgcat(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
(void)msg_open(sp, str);
1994-08-17 20:17:19 +04:00
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_paragraph __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_paragraph(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
if (strlen(str) & 1) {
msgq(sp, M_ERR,
1996-05-20 06:01:36 +04:00
"048|The paragraph option must be in two character groups");
1994-08-17 20:17:19 +04:00
return (1);
}
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_print __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_print(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
/* Reinitialize the key fast lookup table. */
v_key_ilookup(sp);
1994-08-17 20:17:19 +04:00
1996-05-20 06:01:36 +04:00
/* Reformat the screen. */
F_SET(sp, SC_SCR_REFORMAT);
1994-08-17 20:17:19 +04:00
return (0);
}
/*
1996-05-20 06:01:36 +04:00
* PUBLIC: int f_readonly __P((SCR *, OPTION *, char *, u_long *));
1994-08-17 20:17:19 +04:00
*/
1996-05-20 06:01:36 +04:00
int
f_readonly(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
/*
* !!!
* See the comment in exf.c.
*/
if (*valp)
F_CLR(sp, SC_READONLY);
else
F_SET(sp, SC_READONLY);
1994-08-17 20:17:19 +04:00
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_recompile __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_recompile(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
if (F_ISSET(sp, SC_RE_SEARCH)) {
regfree(&sp->re_c);
F_CLR(sp, SC_RE_SEARCH);
1994-08-17 20:17:19 +04:00
}
1996-05-20 06:01:36 +04:00
if (F_ISSET(sp, SC_RE_SUBST)) {
regfree(&sp->subre_c);
F_CLR(sp, SC_RE_SUBST);
1994-08-17 20:17:19 +04:00
}
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_reformat __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_reformat(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
F_SET(sp, SC_SCR_REFORMAT);
1994-08-17 20:17:19 +04:00
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_section __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_section(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
if (strlen(str) & 1) {
msgq(sp, M_ERR,
"049|The section option must be in two character groups");
return (1);
1994-08-17 20:17:19 +04:00
}
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_ttywerase __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_ttywerase(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
if (!*valp)
O_CLR(sp, O_ALTWERASE);
1994-08-17 20:17:19 +04:00
return (0);
}
1996-05-20 06:01:36 +04:00
/*
* PUBLIC: int f_w300 __P((SCR *, OPTION *, char *, u_long *));
*/
int
f_w300(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
u_long v;
1996-05-20 06:01:36 +04:00
/* Historical behavior for w300 was < 1200. */
if (sp->gp->scr_baud(sp, &v))
1994-08-17 20:17:19 +04:00
return (1);
1996-05-20 06:01:36 +04:00
if (v >= 1200)
1994-08-17 20:17:19 +04:00
return (0);
1996-05-20 06:01:36 +04:00
return (f_window(sp, op, str, valp));
1994-08-17 20:17:19 +04:00
}
/*
1996-05-20 06:01:36 +04:00
* PUBLIC: int f_w1200 __P((SCR *, OPTION *, char *, u_long *));
1994-08-17 20:17:19 +04:00
*/
1996-05-20 06:01:36 +04:00
int
f_w1200(sp, op, str, valp)
1994-08-17 20:17:19 +04:00
SCR *sp;
1996-05-20 06:01:36 +04:00
OPTION *op;
1994-08-17 20:17:19 +04:00
char *str;
1996-05-20 06:01:36 +04:00
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
u_long v;
1994-08-17 20:17:19 +04:00
1996-05-20 06:01:36 +04:00
/* Historical behavior for w1200 was == 1200. */
if (sp->gp->scr_baud(sp, &v))
1994-08-17 20:17:19 +04:00
return (1);
1996-05-20 06:01:36 +04:00
if (v < 1200 || v > 4800)
return (0);
1994-08-17 20:17:19 +04:00
1996-05-20 06:01:36 +04:00
return (f_window(sp, op, str, valp));
1994-08-17 20:17:19 +04:00
}
/*
1996-05-20 06:01:36 +04:00
* PUBLIC: int f_w9600 __P((SCR *, OPTION *, char *, u_long *));
1994-08-17 20:17:19 +04:00
*/
1996-05-20 06:01:36 +04:00
int
f_w9600(sp, op, str, valp)
SCR *sp;
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
u_long v;
1994-08-17 20:17:19 +04:00
1996-05-20 06:01:36 +04:00
/* Historical behavior for w9600 was > 1200. */
if (sp->gp->scr_baud(sp, &v))
1994-08-17 20:17:19 +04:00
return (1);
1996-05-20 06:01:36 +04:00
if (v <= 4800)
return (0);
return (f_window(sp, op, str, valp));
1994-08-17 20:17:19 +04:00
}
/*
1996-05-20 06:01:36 +04:00
* PUBLIC: int f_window __P((SCR *, OPTION *, char *, u_long *));
1994-08-17 20:17:19 +04:00
*/
1996-05-20 06:01:36 +04:00
int
f_window(sp, op, str, valp)
1994-08-17 20:17:19 +04:00
SCR *sp;
1996-05-20 06:01:36 +04:00
OPTION *op;
char *str;
u_long *valp;
1994-08-17 20:17:19 +04:00
{
1996-05-20 06:01:36 +04:00
if (*valp >= O_VAL(sp, O_LINES) - 1 &&
(*valp = O_VAL(sp, O_LINES) - 1) == 0)
*valp = 1;
return (0);
1994-08-17 20:17:19 +04:00
}