m_cc.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* m_cc.c
*
* XCurses Library
*
* Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
*
*/
#if M_RCSID
#ifndef lint
#endif
#endif
#include <private.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <m_wio.h>
typedef struct {
int max;
int used;
char *mbs;
} t_string;
static int
int byte;
{
return EOF;
return byte;
}
/*
* Convert a wint_t string into a multibyte string.
*
* The conversion stops at the end of string or the first WEOF.
* Return the number of bytes successfully placed into mbs.
*/
int
char *mbs;
int n;
{
int last;
for (;; ++wis) {
/* In case of error, rewind string to the last character. */
break;
}
/* Test for end of string AFTER trying to copy into the
* buffer, because m_wio_put() has to handle state changes
* back to the initial state on '\0' or WEOF.
*/
break;
}
/* m_wio_put() does not write '\0', because the "stream"
* object is considered to be in "text" mode, which in the
* case of file I/O produces undefined results for systems
* using locking-shift character sets.
*/
}
/*
* Convert a wint_t string (filled in by wgetn_wstr()) to a wchar_t string.
* The conversion stops at the end of string or the first WEOF. Return the
* number of successfully copied characters.
*
* This routinue should be used when sizeof (wchar_t) < sizeof (wint_t).
*/
int
int n;
{
if (n < 0)
n = INT_MAX;
break;
}
*wcs = '\0';
}
/*
* Convert a chtype to a cchar_t.
*/
int
{
char mb;
return ERR;
return OK;
}
/*
* Return a complex character as a chtype.
*/
{
unsigned char mb[MB_LEN_MAX];
/* Is it a single-byte character? */
return ch;
}
/*
* Convert a complex character's "character" into a multibyte string.
* The attribute and colour are ignored.
*
* If 0 < n, set a new multibyte string and convert the first character,
* returning either -1 on error or the number of bytes used to convert the
* character.
*
* If n == 0, continue appending to the current multibyte string and return
* a value as for 0 < n case.
*
* If n < 0, return the accumulated byte length of the current multibyte
* string and do nothing else.
*
* When converting a character, a null cchar_t pointer will force the initial
* shift state and append a '\0' to the multibyte string. The return value
* will instead by the number of bytes used to shift to the initial state,
* and exclude the '\0'.
*/
int
char *mbs;
int n;
{
if (n < 0) {
/* Return total number of bytes written to multibyte string. */
} else if (0 < n) {
/* Start a new conversion. */
} /* else n == 0, continue appending to previous mbs. */
/* In case of error, rewind string to the last character. */
/* Force initial shift state. */
return -1;
}
} else {
return -1;
}
}
return count;
}
/*
* Convert a stty character into a wchar_t.
*/
int
int index;
{
char mb;
int code;
/* Refer to _shell instead of _prog, since _shell will
* correctly reflect the user's prefered settings, whereas
* _prog may not have been initialised if both input and
* output have been redirected.
*/
return code;
}
/*
* Build a cchar_t from the leading spacing and non-spacing characters
* in the multibyte character string. Only one spacing character is copied
* from the multibyte character string.
*
* Return the number of characters copied from the string, or -1 on error.
*/
int
{
const char *start;
/* Too many characters. */
return -1;
/* Invalid multibyte sequence. */
return -1;
if (nbytes == 0)
/* Remainder of string evaluates to the null byte. */
break;
/* Treat control codes like a spacing character. */
width = 1;
return -1;
/* Do we have a spacing character? */
if (0 < width) {
if (have_one)
break;
have_one = 1;
}
}
(void) __m_cc_sort(cc);
}
/*
* Build a cchar_t from the leading spacing and non-spacing characters
* in the wide character string. Only one spacinig character is copied
* from the wide character string.
*
* Return the number of characters copied from the string, or -1 on error.
*/
int
{
short i;
/* Too many characters. */
return -1;
return -1;
if (0 < width) {
if (have_one)
break;
have_one = 1;
}
}
(void) __m_cc_sort(cc);
}
/*
* Convert a single wide character into a complex character.
*/
int
{
return -1;
return 0;
}
/*
* Sort a complex character into a spacing character followed
* by any non-spacing characters in increasing order of oridinal
* values. This facilitates both comparision and writting of
* complex characters. More than one spacing character is
* considered an error.
*
* Return the spacing character's column width or -1 if more
* than one spacing character appears in cc.
*/
int
{
/* Find spacing character and place in as first element. */
if (0 < j) {
/* More than one spacing character is an error. */
if (0 < width)
return -1;
spacing = 1;
width = j;
break;
}
}
/* Bubble sort small array. */
}
}
}
return width;
}
/*
* Return width inn screen columns of the character.
*/
int
{
}
/*
* Return the first column of a multi-column character, in window.
*/
int
__m_cc_first(w, y, x)
WINDOW *w;
int y, x;
{
break;
}
return x;
}
/*
* Return the start of the next multi-column character, in window.
*/
int
__m_cc_next(w, y, x)
WINDOW *w;
int y, x;
{
break;
}
return x;
}
/*
* Return true if valid last column of a multi-column character.
*/
int
__m_cc_islast(w, y, x)
WINDOW *w;
int y, x;
{
first = __m_cc_first(w, y, x);
}
/*
* Replace the character at the current cursor location
* according to the column width of the character. The
* cursor does not advance.
*
* Return -1 if the character won't fit on the line and the background
* was written in its place; else return the width of the character in
* screen columns.
*/
int
WINDOW *w;
int y, x;
int as_is;
{
int i, width;
/* If we try to write a broad character that would exceed the
* right margin, then write the background character instead.
*/
return -1;
}
/* Erase the region to be occupied by the new character.
* __m_cc_erase() will erase whole characters so that
* writing a multicolumn character that overwrites the
* trailing and leading portions of two already existing
* multicolumn characters, erases the remaining portions.
*/
/* Write the first column of the character. */
} else {
}
/* Mark this as the first column of the character. */
/* Duplicate the character in every column the character occupies. */
}
return width;
}
int
{
if (w->_maxx <= x)
x = w->_maxx-1;
++y;
if (y == w->_bottom) {
--y;
if (w->_flags & W_CAN_SCROLL) {
return ERR;
x = 0;
}
} else if (w->_maxy <= y) {
y = w->_maxy-1;
} else {
/* The cursor wraps for any line (in and out of the scroll
* region) except for the last line of the scroll region.
*/
x = 0;
}
*yp = y;
*xp = x;
return OK;
}
/*
* Add the character at the current cursor location
* according to the column width of the character.
* The cursor will be advanced.
*
* Return ERR if adding the character causes the
* screen to scroll, when it is disallowed.
*/
int
WINDOW *w;
int y, x;
{
#ifdef M_CURSES_TRACE
"__m_cc_add(%p, %d, %d, %p, %d, %p, %p)",
);
#endif
case '\t':
goto error;
x = nx;
if (w->_maxx <= x) {
if (__m_do_scroll(w, y, x, &y, &x) == ERR)
goto error;
}
break;
case '\n':
goto error;
if (__m_do_scroll(w, y, x, &y, &x) == ERR)
goto error;
break;
case '\r':
x = 0;
break;
case '\b':
if (0 < x)
--x;
break;
default:
x += width;
if (__m_do_scroll(w, y, x, &y, &x) == ERR)
goto error;
if (width < 0)
}
}
*yp = y;
*xp = x;
}
/*
* Erase region from (y,x) to (ly, lx) inclusive. The
* region is extended left and right in the case where
* the portions of a multicolumn characters are erased.
*
* Return -1 if the region is not an integral multiple
* of the background character, else zero for success.
*/
int
WINDOW *w;
{
int i, width;
if (ly < y)
return -1;
/* Erase from first whole character (inclusive) to next
* character (exclusive).
*/
x = __m_cc_first(w, y, x);
/* Is the region to blank out an integral width of the
* background character?
*/
return -1;
return -1;
for (; y < ly; ++y, x = 0) {
if (x < w->_first[y])
w->_first[y] = (short) x;
/* The start of each new character will be set true
* while internal columns of the character will be
* reset to false.
*/
}
if (w->_last[y] < x)
w->_last[y] = (short) x;
}
if (x < w->_first[y])
w->_first[y] = (short) x;
/* The start of each new character will be set true
* while internal columns of the character will be
* reset to false.
*/
}
if (w->_last[y] < x)
w->_last[y] = (short) x;
return 0;
}
/*
* Expand the character to the left or right of the given position.
* Return the value returned by __m_cc_replace().
*/
int
__m_cc_expand(w, y, x, side)
WINDOW *w;
int y, x, side;
{
if (side < 0)
else if (0 < side)
dx = __m_cc_first(w, y, x);
else
return -1;
/* __m_cc_replace() will erase the region containing
* the character we want to expand.
*/
}
/*
* Return true if characters are equal.
*
* NOTE to guarantee correct results, make sure that both
* characters have been passed through __m_cc_sort().
*/
int
int exact;
{
int i;
return 0;
return 0;
return 0;
return 0;
return 0;
return 1;
}
/*
* Write to the stream the character portion of a cchar_t.
*/
int
{
size_t i, j;
char mb[MB_LEN_MAX];
errno = 0;
if (errno != 0)
return EOF;
return EOF;
}
return 0;
}