ex_vops3.c revision f6db9f272f0061301cfaa1c0001b7d636eae31f4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1981 Regents of the University of California */
#pragma ident "%Z%%M% %I% %E% SMI"
#include "ex.h"
#include "ex_tty.h"
#include "ex_vis.h"
/*
* Routines to handle structure.
* Operations supported are:
* ( ) { } [ ]
*
* These cover: LISP TEXT
* ( ) s-exprs sentences
* { } list at same paragraphs
* [ ] defuns sections
*
* { and } for C used to attempt to do something with matching {}'s, but
* I couldn't find definitions which worked intuitively very well, so I
* scrapped this.
*
* The code here is very hard to understand.
*/
int (*lf)();
int lindent();
bool wasend;
int endsent(bool);
/*
* Find over structure, repeated count times.
* Don't go past line limit. F is the operation to
* be performed eventually. If pastatom then the user said {}
* rather than (), implying past atoms in a list (or a paragraph
* rather than a sentence.
*/
int
bool pastatom;
int cnt, (*f)();
{
int c;
int rc = 0;
/*
* Initialize, saving the current line buffer state
* and computing the limit; a 0 argument means
* directional end of file.
*/
wasend = 0;
lf = f;
if (limit == 0)
if (pastatom >= 2) {
if (pastatom == 3) {
;
}
} else {
cnt--;
}
wdot = 0;
rc = -1;
}
}
unsigned char *icurs;
if (linebuf[0] == 0) {
do
if (!lnext())
goto ret;
while (linebuf[0] == 0);
if (dir > 0) {
wdot--;
linebuf[0] = 0;
/*
* If looking for sentence, next line
* starts one.
*/
if (!pastatom) {
goto begin;
}
}
}
/*
* Advance so as to not find same thing again.
*/
if (dir > 0) {
if (!lnext()) {
rc = -1;
goto ret;
}
#ifdef XPG4
} else {
if (!lnext()) {
rc = -1;
goto ret;
}
(void) ltosol1("");
}
#else /* ! XPG4 */
} else
(void)lskipa1("");
#endif /* XPG4 */
/*
*/
for (;;) {
if (!lnext())
goto ret;
if (--cnt <= 0)
break;
if (linebuf[0] == 0) {
do
if (!lnext())
goto ret;
while (linebuf[0] == 0);
} else
if (!lnext())
goto ret;
}
/*
* If going backwards, and didn't hit the end of the buffer,
* then reverse direction.
*/
dir = 1;
/*
* Empty line needs special treatement.
* If moved to it from other than beginning of next line,
* then a sentence starts on next line.
*/
(void) lnext();
goto ret;
}
}
/*
* advance to next.
*/
(void)lskipa1("");
}
else {
c = *wcursor;
/*
* Startup by skipping if at a ( going left or a ) going
* right to keep from getting stuck immediately.
*/
if (!lnext()) {
rc = -1;
goto ret;
}
}
/*
* Now chew up repetition count. Each time around
* if at the beginning of an s-exp (going forwards)
* or the end of an s-exp (going backwards)
* if we hit a higher level paren, else skip an atom,
* counting it unless pastatom.
*/
while (cnt > 0) {
c = *wcursor;
if (!lskipbal("()"))
goto ret;
/*
* Unless this is the last time going
* backwards, skip past the matching paren
* so we don't think it is a higher level paren.
*/
goto ret;
goto ret;
--cnt;
/* Found a higher level paren */
goto ret;
else {
if (!lskipatom())
goto ret;
if (!pastatom)
--cnt;
}
}
}
ret:
return (rc);
}
/*
* Is this the end of a sentence?
*/
int
{
int c, d;
int len;
/*
* If this is the beginning of a line, then
* check for the end of a paragraph or section.
*/
return (endPS());
/*
* Sentences end with . ! ? not at the beginning
* of the line, and must be either at the end of the line,
* or followed by 2 spaces. Any number of intervening ) ] ' "
* characters are allowed.
*/
goto tryps;
do {
len = 1;
if ((d = *cp) == 0)
return (1);
#ifdef XPG4
} while (any(d, ")]'\""));
#else /* ! XPG4 */
} while (any(d, ")]'"));
#endif /* XPG4 */
return (1);
if (cp[1] == 0)
return (endPS());
return (0);
}
/*
* End of paragraphs/sections are respective
* macros as well as blank lines and form feeds.
*/
int
endPS(void)
{
return (linebuf[0] == 0 ||
#ifdef XPG4
/* POSIX 1003.2 Section 5.35.7.1: control-L, "{" */
linebuf[0] == '{' ||
#endif /* XPG4 */
}
int
{
int i;
unsigned char *cp;
int cnt = 0;
addr--;
if (*cp == '(')
cnt++;
else if (*cp == ')')
cnt--;
if (*cp == 0)
goto again;
if (cnt == 0)
addr++;
}
linebuf[0] = 0;
dir = -1;
if (!lskipbal("()"))
i = 0;
i = 2;
else {
dir = 1;
i = 1;
} else
i = 0;
if (!inopen)
i--;
}
return (i);
}
int
{
int i;
if (*cp == 0)
return (0);
i = 1;
cp += i;
}
lf = 0;
parens = any(*cp, "()") ? (unsigned char *)"()" : any(*cp, "[]") ? (unsigned char *)"[]" : (unsigned char *)"{}";
dir = -1;
} else {
dir = 1;
}
if (addr)
if (splitw)
return (i);
}
void
{
*wcursor = 0;
int i = insmode;
int c = outcol;
int l = outline;
if (!move_insert_mode)
endim();
flush();
sleep(1);
vgoto(l, c);
if (i)
goim();
}
else {
(void) beep();
}
wdot = 0;
wcursor = 0;
}
int
ltosolid(void)
{
return (ltosol1("()"));
}
int
{
unsigned char *cp;
int len;
unsigned char *ocp;
return (0);
if (!lnext())
return (0);
return (1);
len = 1;
continue;
}
len = 1;
}
return (1);
}
int
{
int c;
do {
if (!lnext()) {
return (0);
}
c = *wcursor;
if (c == parens[1])
level--;
else if (c == parens[0])
level++;
} while (level);
return (1);
}
int
lskipatom(void)
{
return (lskipa1("()"));
}
int
{
int c;
for (;;) {
if (!lnext())
return (0);
break;
}
c = *wcursor;
break;
if (!lnext())
return (0);
break;
}
}
int
lnext(void)
{
if (dir > 0) {
if (*wcursor)
if (*wcursor)
return (1);
return (0);
}
wdot++;
return (1);
} else {
return (1);
return (0);
}
wdot--;
if(!*linebuf)
else {
}
return (1);
}
}
int
lbrack(int c, int (*f)())
{
for (;;) {
break;
}
if (linebuf[0] == '{' ||
#ifdef XPG4
/* POSIX 1003.2 Section 5.35.7.1: control-L */
#endif /* XPG4 */
if (c == ']' && f != vmove) {
addr--;
}
break;
}
break;
}
return (0);
if (f != vmove)
else
wcursor = 0;
vmoving = 0;
return (1);
}
int
{
if (linebuf[0] != '.')
return (0);
return (1);
return (1);
}
return (0);
}