BSD 4_4 release
[unix-history] / usr / src / contrib / nvi / nvi / svi / svi_get.c
CommitLineData
ad787160
C
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef lint
35static char sccsid[] = "@(#)svi_get.c 8.1 (Berkeley) 6/9/93";
36#endif /* not lint */
37
38#include <sys/types.h>
39
40#include <ctype.h>
41#include <curses.h>
42#include <errno.h>
43#include <stdlib.h>
44
45#include "vi.h"
46#include "vcmd.h"
47#include "svi_screen.h"
48
49/*
50 * svi_get --
51 * Fill a buffer from the terminal for vi. The approach is that we
52 * fake like the user is doing input on the last line of the screen.
53 * This makes all of the scrolling work correctly, and allows us the
54 * use of the vi text editing routines, not to mention essentially
55 * infinite length ex commands.
56 */
57int
58svi_get(sp, ep, hp, prompt, flags)
59 SCR *sp;
60 EXF *ep;
61 HDR *hp;
62 int prompt;
63 u_int flags;
64{
65 MARK save;
66 recno_t bot_lno, top_lno;
67 size_t bot_off, top_off;
68 int eval;
69
70 /* Save where we are. */
71 bot_lno = TMAP->lno;
72 bot_off = TMAP->off;
73 top_lno = HMAP->lno;
74 top_off = HMAP->off;
75 save.lno = sp->lno;
76 save.cno = sp->cno;
77
78 /* Fake it. */
79 sp->t_smap[1].lno = sp->t_smap[0].lno + 1;
80 sp->t_smap[1].off = 1;
81 sp->lno = sp->t_smap[0].lno + 1;
82 sp->cno = 0;
83 ++sp->t_smap;
84 ++sp->t_rows;
85
86 /*
87 * Historic vi allowed you to use abbreviations on the command line.
88 * To implement this, add TXT_MAPINPUT to the flags for the v_ntext()
89 * routine. This is necessary but not sufficient -- v_ntext() will
90 * have to be modified to make available a copy of the original line
91 * without abbreviations, or the :unabbreviate command won't work.
92 */
93 eval = v_ntext(sp, ep, &sp->bhdr, NULL, NULL,
94 0, NULL, prompt, 0, flags | TXT_APPENDEOL | TXT_CR | TXT_ESCAPE);
95
96 /* Put it all back. */
97 --sp->t_rows;
98 --sp->t_smap;
99 sp->lno = save.lno;
100 sp->cno = save.cno;
101
102 /*
103 * The map may be wrong if the user entered more than one
104 * (logical) line. Fix it. If the user entered a whole
105 * screen, this will be slow, but it's not worth caring.
106 */
107 while (bot_lno != TMAP->lno || bot_off != TMAP->off)
108 if (svi_sm_1down(sp, ep))
109 return (1);
110
111 if (svi_refresh(sp, ep))
112 return (1);
113
114 return (eval);
115}