/*
* 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 (c) 1988 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.7 */
/*LINTLIBRARY*/
#include "utility.h"
/* _data_beg - return ptr to first non-blank char in v[n] (v on failure) */
char *
_data_beg(char *v, int n)
{
char *vend = v + n;
while (v < vend && *v == ' ') ++v;
return (v == vend ? v - n : v);
}
/*
* _data_end - return ptr to char after last
* non-blank char in v[n] (v on failure)
*/
char *
_data_end(char *v, int n)
{
char *vend = v + n;
return (vend);
}
/* _whsp_beg - return ptr to first blank in v[n] (v on failure) */
char *
_whsp_beg(char *v, int n)
{
char * vend = v + n;
while (v < vend && *v != ' ') ++v;
return (v == vend ? v - n : v);
}
/* _whsp_end - return ptr to char after last blank in v[n] (v on failure) */
char *
_whsp_end(char *v, int n)
{
char * vend = v + n;
return (vend);
}
/*
* _adjust_cursor - adjust cursor based on
* offset of v from beginning of field buffer
*/
void
{
if (Y(f) >= Ymax(f))
Y(f) = 0;
}
/*
* _buf_to_win - copy buffer to window(trailing
* blanks on each line are not copied)
*/
void
{
char * v = Buf(f);
for (y = 0; y < ymax; ++y) {
(void) wmove(w, y, 0);
(void) waddnstr(w, v, n);
}
v += xmax;
}
}
/* _win_to_buf - copy window to buffer */
void
{
int i;
char * v = Buf(f);
(void) wmove(w, 0, 0);
if (pad != ' ')
for (i = 0; i < size; ++i, ++v)
if (*v == pad)
*v = ' '; /* replace pad char with blank */
}
/* _pos_form_cursor - move to cursor position and sync up cursor */
int
{
WINDOW * w = W(f);
FIELD * c = C(f);
if (!w)
return (E_SYSTEM_ERROR);
(void) wmove(w, Y(f), X(f));
if (Scrollable(c)) {
if (OneRow(c)) {
} else {
}
wcursyncup(Sub(f));
} else
wcursyncup(w);
} else {
wcursyncup(Sub(f));
}
return (E_OK);
}
/* _update_current - sync up current field */
int
{
WINDOW * w = W(f);
FIELD * c = C(f);
if (!w)
return (E_SYSTEM_ERROR);
if (Scrollable(c)) {
if (OneRow(c)) {
if (X(f) < B(f))
B(f) = X(f);
else if (X(f) >= xmax)
B(f) = X(f) - c->cols + 1;
FALSE);
} else {
if (Y(f) < T(f)) {
T(f) = Y(f);
}
if (Y(f) >= ymax) {
T(f) = Y(f) - c -> rows + 1;
}
ys = T(f);
} else {
/* intersect changed lines with visible lines */
if (is_linetouched(w, ys))
break;
if (! is_linetouched(w, ye))
break;
}
}
}
} else
wsyncup(w);
}
(void) untouchwin(w);
return (_pos_form_cursor(f));
}
/* justify - justify field f in window w as given by Just(f) */
static void
{
int n = (int) (vend - v);
int x = 0;
if (n) {
switch (Just(f)) {
case JUSTIFY_LEFT:
break;
case JUSTIFY_CENTER:
x = (f -> cols - n) / 2;
break;
case JUSTIFY_RIGHT:
x = f -> cols - n;
break;
}
(void) wmove(w, 0, x);
(void) waddnstr(w, v, n);
}
}
/* unjustify - left justify field f in window w for editing */
static void
{
int n = (int) (vend - v);
if (n) {
(void) wmove(w, 0, 0);
(void) waddnstr(w, v, n);
}
}
/* _sync_buffer - sync current field with characters in window */
void
{
_win_to_buf(W(f), C(f));
(void) wmove(W(f), Y(f), X(f));
}
}
/* _sync_linked - sync fields linked to field f */
int
{
int err = 0;
while (p != f) {
if (_sync_field(p) != E_OK)
++err;
p = p -> link;
}
}
/* display_field - display field f */
static int
{
if (!w)
return (FALSE);
(void) werase(w);
if (Justified(f))
justify(f, w);
else
_buf_to_win(f, w);
}
wsyncup(w);
(void) delwin(w);
return (TRUE);
}
/* erase_field - erase field f */
static int
{
if (!w)
return (FALSE);
(void) werase(w);
wsyncup(w);
(void) delwin(w);
return (TRUE);
}
/* _sync_field - sync the field after a change to the field buffer */
int
{
int v = TRUE;
if (isCurrent(f)) {
WINDOW * w = W(p);
Y(p) = 0;
X(p) = 0;
T(p) = 0;
B(p) = 0;
(void) werase(w);
unjustify(f, w);
else
_buf_to_win(f, w);
(void) _update_current(p);
} else
v = display_field(f);
}
return (v ? E_OK : E_SYSTEM_ERROR);
}
/* _sync_attrs - sync the field after a change to a field attribute */
int
{
int v = TRUE;
if (isCurrent(f)) {
WINDOW * w = W(p);
_sync_buffer(p);
(void) werase(w);
if (Justified(f))
unjustify(f, w);
else
_buf_to_win(f, w);
} else {
FALSE);
_buf_to_win(f, w);
}
(void) _update_current(p);
} else
v = display_field(f);
}
return (v ? E_OK : E_SYSTEM_ERROR);
}
int
{
int v = TRUE;
/* x & opt indicates option opt has changed state */
if (Connected(f)) {
if (isCurrent(f)) {
return (E_CURRENT);
}
if (x & O_VISIBLE) {
v = display_field(f);
else
v = erase_field(f);
} else if (x & O_PUBLIC) {
v = display_field(f);
}
}
}
if (x & O_STATIC) {
(void) display_field(f);
}
(void) display_field(f);
}
}
}
return (v ? E_OK : E_SYSTEM_ERROR);
}
/* _validate - validate current field */
int
{
FIELD * c = C(f);
_sync_buffer(f);
if (CheckField(c)) {
(void) _sync_linked(c);
} else
return (FALSE);
}
return (TRUE);
}
/*
* _set_current_field - change current field on form f to given field.
* POSTED flag is set unless this is called from post_form().
*/
int
{
WINDOW * w = W(f);
FIELD * c = C(f);
if (w) {
if (Visible(c)) {
(void) _update_current(f);
if (Scrollable(c)) {
if (T(f) == 0)
else
} else if (Justified(c)) {
(void) werase(w);
justify(c, w);
wsyncup(w);
}
}
}
(void) delwin(w);
}
c = field;
else
c -> fcol);
if (!w)
return (E_SYSTEM_ERROR);
C(f) = c;
W(f) = w;
(void) werase(w);
_buf_to_win(c, w);
} else if (Justified(c)) {
(void) werase(w);
unjustify(c, w);
wsyncup(w);
}
(void) untouchwin(w);
}
Y(f) = 0;
X(f) = 0;
T(f) = 0;
B(f) = 0;
return (E_OK);
}
/*
* _set_form_page - display given page and set current field to c.
* if c is null, then set current field to first field on page.
* POSTED flag is set unless this is called from post_form().
*/
int
{
FIELD * p = x;
P(f) = page;
do {
if (!display_field(p))
return (E_SYSTEM_ERROR);
p = p -> snext;
} while (p != x);
return (c ? _set_current_field(f, c) : _first_field(f));
}
return (E_OK);
}