* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)v_paragraph.c 8.4 (Berkeley) 12/9/93";
* Paragraphs are empty lines after text or values from the paragraph or
* v_paragraphf -- [count]}
* Move forward count paragraphs.
v_paragraphf(sp
, ep
, vp
, fm
, tm
, rp
)
enum { P_INTEXT
, P_INBLANK
} pstate
;
recno_t cnt
, lastlno
, lno
;
/* Figure out what state we're currently in. */
if ((p
= file_gline(sp
, ep
, lno
, &len
)) == NULL
)
* If we start in text, we want to switch states 2 * N - 1
* times, in non-text, 2 * N times.
cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1;
if (len
== 0 || v_isempty(p
, len
))
if ((p
= file_gline(sp
, ep
, ++lno
, &len
)) == NULL
)
if (p
[0] == '.' && len
>= 2)
for (lp
= VIP(sp
)->paragraph
; *lp
; lp
+= 2)
(lp
[1] == ' ' || lp
[1] == p
[2]) &&
if (len
== 0 || v_isempty(p
, len
)) {
if (len
== 0 || v_isempty(p
, len
))
* Historically, a motion command was up to the end
* of the previous line, whereas the movement command
* was to the start of the new "paragraph".
found
: if (F_ISSET(vp
, VC_C
| VC_D
| VC_Y
)) {
rp
->cno
= lastlen
? lastlen
+ 1 : 0;
* EOF is a movement sink, however, the } command historically
* moved to the end of the last line if repeatedly invoked.
eof
: if (fm
->lno
!= lno
- 1) {
rp
->cno
= len
? len
- 1 : 0;
if ((p
= file_gline(sp
, ep
, fm
->lno
, &len
)) == NULL
)
GETLINE_ERR(sp
, fm
->lno
);
if (fm
->cno
!= (len
? len
- 1 : 0)) {
rp
->cno
= len
? len
- 1 : 0;
* v_paragraphb -- [count]{
* Move forward count paragraph.
v_paragraphb(sp
, ep
, vp
, fm
, tm
, rp
)
enum { P_INTEXT
, P_INBLANK
} pstate
;
* The { command historically moved to the beginning of the first
* line if invoked on the first line.
/* Figure out what state we're currently in. */
if ((p
= file_gline(sp
, ep
, lno
, &len
)) == NULL
)
* If we start in text, we want to switch states 2 * N - 1
* times, in non-text, 2 * N times.
cnt
= F_ISSET(vp
, VC_C1SET
) ? vp
->count
: 1;
if (len
== 0 || v_isempty(p
, len
))
if ((p
= file_gline(sp
, ep
, --lno
, &len
)) == NULL
)
if (p
[0] == '.' && len
>= 2)
for (lp
= VIP(sp
)->paragraph
; *lp
; lp
+= 2)
(lp
[1] == ' ' || lp
[1] == p
[2]) &&
if (len
== 0 || v_isempty(p
, len
)) {
if (len
!= 0 && !v_isempty(p
, len
)) {
/* SOF is a movement sink. */
* Build the paragraph command search pattern.
* The vi paragraph command searches for either a paragraph or
p_len
= (p_p
= O_STR(sp
, O_PARAGRAPHS
)) == NULL
? 0 : strlen(p_p
);
s_len
= (s_p
= O_STR(sp
, O_SECTIONS
)) == NULL
? 0 : strlen(s_p
);
if (p_len
== 0 && s_len
== 0)
MALLOC_RET(sp
, p
, char *, p_len
+ s_len
+ 1);
if (vip
->paragraph
!= NULL
)
FREE(vip
->paragraph
, vip
->paragraph_len
);
memmove(p
, p_p
, p_len
+ 1);
memmove(p
+ p_len
, s_p
, s_len
+ 1);
vip
->paragraph_len
= p_len
+ s_len
+ 1;