2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright (c) 1997, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include "utility.h"
2N/A
2N/A#define SizePrev(f, v) ((v) - Buf(f)) /* from beginning to v */
2N/A#define SizeNext(f, v) (BufSize(f) - SizePrev(f, v))
2N/A /* from v through end */
2N/A#define OffscreenRows(c) ((c)->drows - (c)->rows)
2N/A#define OffscreenCols(c) ((c)->dcols - (c)->cols)
2N/A
2N/A/* _next_char move to next char with wrap to next line at end of line */
2N/Aint
2N/A_next_char(FORM *f)
2N/A{
2N/A if (++X(f) == Xmax(f)) {
2N/A if (++Y(f) == Ymax(f)) {
2N/A --X(f);
2N/A --Y(f);
2N/A return (E_REQUEST_DENIED); /* at last char */
2N/A }
2N/A X(f) = 0;
2N/A }
2N/A return (E_OK);
2N/A}
2N/A
2N/A/*
2N/A * _prev_char - move to previous char with
2N/A * wrap to previous line at beginning of line
2N/A */
2N/Aint
2N/A_prev_char(FORM *f)
2N/A{
2N/A if (--X(f) < 0) {
2N/A if (--Y(f) < 0) {
2N/A ++X(f);
2N/A ++Y(f);
2N/A return (E_REQUEST_DENIED); /* at first char */
2N/A }
2N/A X(f) = Xmax(f) - 1;
2N/A }
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _next_line - move to beginning of next line */
2N/Aint
2N/A_next_line(FORM *f)
2N/A{
2N/A if (++Y(f) == Ymax(f)) {
2N/A --Y(f);
2N/A return (E_REQUEST_DENIED); /* at last line */
2N/A }
2N/A X(f) = 0;
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _prev_line - move to beginning of previous line */
2N/Aint
2N/A_prev_line(FORM *f)
2N/A{
2N/A if (--Y(f) < 0) {
2N/A ++Y(f);
2N/A return (E_REQUEST_DENIED); /* at first line */
2N/A }
2N/A X(f) = 0;
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _next_word - move to beginning of next word */
2N/Aint
2N/A_next_word(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A char * v = LineBuf(c, Y(f)) + X(f); /* position in buffer */
2N/A char * t;
2N/A
2N/A _sync_buffer(f);
2N/A
2N/A t = _whsp_beg(v, (int) SizeNext(c, v));
2N/A v = _data_beg(t, (int) SizeNext(c, t));
2N/A
2N/A if (v == t)
2N/A return (E_REQUEST_DENIED); /* at last word */
2N/A
2N/A if (OneRow(c) && c->dcols != c->cols) {
2N/A /* one row and field has grown */
2N/A t = v;
2N/A
2N/A while (*t != ' ' && *t != '\0') /* find end of word + 1 */
2N/A t++;
2N/A
2N/A if (t - (Buf(c) + B(f)) > c->cols) {
2N/A if (t - v > c->cols) {
2N/A /* word longer than visible field */
2N/A B(f) = (int) (v - Buf(c));
2N/A } else {
2N/A B(f) = (int) (t - (Buf(c) + c->cols));
2N/A }
2N/A
2N/A X(f) = (int) (v - Buf(c));
2N/A return (E_OK);
2N/A }
2N/A }
2N/A
2N/A _adjust_cursor(f, v);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _prev_word - move to beginning of previous word */
2N/Aint
2N/A_prev_word(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A char * v = LineBuf(c, Y(f)) + X(f); /* position in buffer */
2N/A char * t;
2N/A
2N/A _sync_buffer(f);
2N/A
2N/A t = _data_end(Buf(c), (int) SizePrev(c, v));
2N/A v = _whsp_end(Buf(c), (int) SizePrev(c, t));
2N/A
2N/A if (v == t)
2N/A return (E_REQUEST_DENIED); /* at first word */
2N/A
2N/A _adjust_cursor(f, v);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _beg_field - move to first non-pad char in field */
2N/Aint
2N/A_beg_field(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A
2N/A _sync_buffer(f);
2N/A _adjust_cursor(f, _data_beg(Buf(c), BufSize(c)));
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _end_field - move after last non-pad char in field */
2N/Aint
2N/A_end_field(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A char * end;
2N/A
2N/A _sync_buffer(f);
2N/A end = _data_end(Buf(c), BufSize(c));
2N/A
2N/A if (end == Buf(c) + BufSize(c))
2N/A end--;
2N/A
2N/A _adjust_cursor(f, end);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _beg_line - move to first non-pad char on current line */
2N/Aint
2N/A_beg_line(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A
2N/A _sync_buffer(f);
2N/A _adjust_cursor(f, _data_beg(LineBuf(c, Y(f)), Xmax(f)));
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _end_line - move after last non-pad char on current line */
2N/Aint
2N/A_end_line(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A char *end;
2N/A
2N/A _sync_buffer(f);
2N/A end = _data_end(LineBuf(c, Y(f)), Xmax(f));
2N/A
2N/A if (end == LineBuf(c, Y(f)) + Xmax(f))
2N/A end--;
2N/A
2N/A _adjust_cursor(f, end);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _left_char - move left */
2N/Aint
2N/A_left_char(FORM *f)
2N/A{
2N/A if (--X(f) < 0) {
2N/A ++X(f);
2N/A return (E_REQUEST_DENIED); /* at left side */
2N/A }
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _right_char - move right */
2N/Aint
2N/A_right_char(FORM *f)
2N/A{
2N/A if (++X(f) == Xmax(f)) {
2N/A --X(f);
2N/A return (E_REQUEST_DENIED); /* at right side */
2N/A }
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _up_char - move up */
2N/Aint
2N/A_up_char(FORM *f)
2N/A{
2N/A if (--Y(f) < 0) {
2N/A ++Y(f);
2N/A return (E_REQUEST_DENIED); /* at top */
2N/A }
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _down_char - move down */
2N/Aint
2N/A_down_char(FORM *f)
2N/A{
2N/A if (++Y(f) == Ymax(f)) {
2N/A --Y(f);
2N/A return (E_REQUEST_DENIED); /* at bottom */
2N/A }
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _scr_fline - scroll forward one line */
2N/Aint
2N/A_scr_fline(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A
2N/A if (++T(f) > OffscreenRows(c)) {
2N/A --T(f);
2N/A return (E_REQUEST_DENIED); /* at bottom */
2N/A }
2N/A ++Y(f);
2N/A Set(c, TOP_CHG);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _scr_bline - scroll backward one line */
2N/Aint
2N/A_scr_bline(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A
2N/A if (--T(f) < 0) {
2N/A ++T(f);
2N/A return (E_REQUEST_DENIED); /* at top */
2N/A }
2N/A --Y(f);
2N/A Set(c, TOP_CHG);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _scr_fpage - scroll forward one page(C(f) -> rows) */
2N/Aint
2N/A_scr_fpage(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A int m = OffscreenRows(c) - T(f);
2N/A int n = c -> rows < m ? c -> rows : m;
2N/A
2N/A if (n) {
2N/A Y(f) += n;
2N/A T(f) += n;
2N/A Set(c, TOP_CHG);
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at bottom */
2N/A}
2N/A
2N/A/* _scr_bpage - scroll backward one page(C(f) -> rows) */
2N/Aint
2N/A_scr_bpage(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A int m = T(f);
2N/A int n = c -> rows < m ? c -> rows : m;
2N/A
2N/A if (n) {
2N/A Y(f) -= n;
2N/A T(f) -= n;
2N/A Set(c, TOP_CHG);
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at top */
2N/A}
2N/A
2N/A/* _scr_fhpage - scroll forward one half page(C(f)->rows + 1)/2) */
2N/Aint
2N/A_scr_fhpage(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A int m = OffscreenRows(c) - T(f);
2N/A int h = (c->rows + 1)/2;
2N/A int n = h < m ? h : m;
2N/A
2N/A if (n) {
2N/A Y(f) += n;
2N/A T(f) += n;
2N/A Set(c, TOP_CHG);
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at bottom */
2N/A}
2N/A
2N/A/* _scr_bhpage - scroll backward one half page(C(f)->rows + 1)/2) */
2N/Aint
2N/A_scr_bhpage(FORM *f)
2N/A{
2N/A FIELD * c = C(f);
2N/A int m = T(f);
2N/A int h = (c->rows + 1)/2;
2N/A int n = h < m ? h : m;
2N/A
2N/A if (n) {
2N/A Y(f) -= n;
2N/A T(f) -= n;
2N/A Set(c, TOP_CHG);
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at top */
2N/A}
2N/A
2N/A/* _scr_fchar - horizontal scroll forward one char */
2N/Aint
2N/A_scr_fchar(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A
2N/A if (++B(f) > OffscreenCols(c)) {
2N/A --B(f);
2N/A return (E_REQUEST_DENIED); /* at end */
2N/A }
2N/A ++X(f);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _scr_bchar - horizontal scroll backward one char */
2N/Aint
2N/A_scr_bchar(FORM *f)
2N/A{
2N/A
2N/A if (--B(f) < 0) {
2N/A ++B(f);
2N/A return (E_REQUEST_DENIED); /* at beginning */
2N/A }
2N/A --X(f);
2N/A return (E_OK);
2N/A}
2N/A
2N/A/* _scr_hfline - horizontal scroll forward one line(C(f)->cols) */
2N/Aint
2N/A_scr_hfline(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A int m = OffscreenCols(c) - B(f);
2N/A int n = c -> cols < m ? c -> cols : m;
2N/A
2N/A if (n) {
2N/A X(f) += n;
2N/A B(f) += n;
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at end */
2N/A}
2N/A
2N/A/* _scr_hbline - horizontal scroll backward one line(C(f)->cols) */
2N/Aint
2N/A_scr_hbline(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A int m = B(f);
2N/A int n = c -> cols < m ? c -> cols : m;
2N/A
2N/A if (n) {
2N/A X(f) -= n;
2N/A B(f) -= n;
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at end */
2N/A}
2N/A
2N/A/* _scr_hfhalf - horizontal scroll forward one half line(C(f)->cols/2) */
2N/Aint
2N/A_scr_hfhalf(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A int m = OffscreenCols(c) - B(f);
2N/A int h = (c->cols + 1)/2;
2N/A int n = h < m ? h : m;
2N/A
2N/A if (n) {
2N/A X(f) += n;
2N/A B(f) += n;
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at end */
2N/A}
2N/A
2N/A/* _scr_hbhalf - horizontal scroll backward one half line(C(f)->cols/2) */
2N/Aint
2N/A_scr_hbhalf(FORM *f)
2N/A{
2N/A FIELD *c = C(f);
2N/A int m = B(f);
2N/A int h = (c->cols + 1)/2;
2N/A int n = h < m ? h : m;
2N/A
2N/A if (n) {
2N/A X(f) -= n;
2N/A B(f) -= n;
2N/A return (E_OK);
2N/A }
2N/A return (E_REQUEST_DENIED); /* at top */
2N/A}