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/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include <stdlib.h>
2N/A#include "curses_inc.h"
2N/A
2N/A/*
2N/A * Initialize usage of soft labels
2N/A * This routine should be called before each call of newscreen
2N/A * or initscr to initialize for the next terminal.
2N/A *
2N/A * ng: number of groupings. If gp is NULL, it denotes one
2N/A * of two default groupings:
2N/A * 0: - - - - - - - -
2N/A * 1: - - - - - - - -
2N/A * gp: groupings.
2N/A */
2N/A
2N/Astatic void _init_slk_func(void);
2N/Astatic int _slk_setpos(int, short *);
2N/Astatic int _ngroups, _groups[LABMAX];
2N/A
2N/Aint
2N/Aslk_start(int ng, int *gp)
2N/A{
2N/A int i = 0, j = 0;
2N/A
2N/A if (gp == NULL) {
2N/A switch (ng) {
2N/A case 2 :
2N/A _ngroups = 2;
2N/A _groups[0] = 4;
2N/A _groups[1] = 4;
2N/A break;
2N/A
2N/A case 3 :
2N/Ano_format :
2N/A _ngroups = 3;
2N/A _groups[0] = 3;
2N/A _groups[1] = 2;
2N/A _groups[2] = 3;
2N/A break;
2N/A
2N/A default :
2N/A if (label_format) {
2N/A int k;
2N/A char ch1[3], *ch = label_format;
2N/A
2N/A /*CONSTCOND*/
2N/A while (TRUE) {
2N/A if ((*ch == ',') ||
2N/A (*ch == '\0')) {
2N/A ch1[i] = '\0';
2N/A if ((k = atoi(ch1)) <=
2N/A 0)
2N/A goto err;
2N/A _groups[j++] = k;
2N/A i = 0;
2N/A if (*ch == '\0') {
2N/A break;
2N/A }
2N/A } else
2N/A ch1[i++] = *ch++;
2N/A }
2N/A } else
2N/A goto no_format;
2N/A break;
2N/A }
2N/A } else {
2N/A for (; i < ng; i++) {
2N/A if ((j += gp[i]) > LABMAX)
2N/Aerr :
2N/A return (ERR);
2N/A _groups[i] = gp[i];
2N/A }
2N/A _ngroups = ng;
2N/A }
2N/A
2N/A /* signal newscreen() */
2N/A _slk_init = _init_slk_func;
2N/A return (OK);
2N/A}
2N/A
2N/Astatic void
2N/A_init_slk_func(void)
2N/A{
2N/A int i, len, num;
2N/A SLK_MAP *slk;
2N/A char *cp, *ep;
2N/A WINDOW *win;
2N/A
2N/A /* clear this out to ready for next time */
2N/A _slk_init = NULL;
2N/A
2N/A /* get space for slk structure */
2N/A if ((slk = (SLK_MAP *) malloc(sizeof (SLK_MAP))) == NULL) {
2N/A curs_errno = CURS_BAD_MALLOC;
2N/A#ifdef DEBUG
2N/A strcpy(curs_parm_err, "_init_slk_func");
2N/A#endif /* DEBUG */
2N/A return;
2N/A }
2N/A
2N/A /* compute actual number of labels */
2N/A num = 0;
2N/A for (i = 0; i < _ngroups; i++)
2N/A num += _groups[i];
2N/A
2N/A /* max label length */
2N/A if (plab_norm && (label_height * label_width >= LABLEN) &&
2N/A (num_labels >= num)) {
2N/A win = NULL;
2N/A goto next;
2N/A } else {
2N/A if ((win = newwin(1, COLS, LINES - 1, 0)) == NULL)
2N/A goto err;
2N/A win->_leave = TRUE;
2N/A (void) wattrset(win, A_REVERSE | A_DIM);
2N/A
2N/A /* remove one line from the screen */
2N/A LINES = --SP->lsize;
2N/A if ((len = (COLS - 1) / (num + 1)) > LABLEN) {
2N/Anext :
2N/A len = LABLEN;
2N/A }
2N/A }
2N/A
2N/A /* positions to place labels */
2N/A if (len <= 0 || num <= 0 || (_slk_setpos(len, slk->_labx) == ERR)) {
2N/A if (win != NULL)
2N/A (void) delwin(win);
2N/Aerr :
2N/A free(slk);
2N/A } else {
2N/A /* LINTED */
2N/A slk->_num = (short) num;
2N/A /* LINTED */
2N/A slk->_len = (short) len;
2N/A
2N/A for (i = 0; i < num; ++i) {
2N/A cp = slk->_ldis[i];
2N/A ep = cp + len;
2N/A for (; cp < ep; ++cp)
2N/A *cp = ' ';
2N/A *ep = '\0';
2N/A slk->_lval[i][0] = '\0';
2N/A slk->_lch[i] = TRUE;
2N/A }
2N/A
2N/A slk->_changed = TRUE;
2N/A slk->_win = win;
2N/A
2N/A _do_slk_ref = _slk_update;
2N/A _do_slk_tch = slk_touch;
2N/A _do_slk_noref = slk_noutrefresh;
2N/A
2N/A SP->slk = slk;
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Compute placements of labels. The general idea is to spread
2N/A * the groups out evenly. This routine is designed for the day
2N/A * when > 8 labels and other kinds of groupings may be desired.
2N/A *
2N/A * The main assumption behind the algorithm is that the total
2N/A * # of labels in all the groups is <= LABMAX.
2N/A *
2N/A * len: length of a label
2N/A * labx: to return the coords of the labels.
2N/A */
2N/A
2N/Astatic int
2N/A_slk_setpos(int len, short *labx)
2N/A{
2N/A int i, k, n, spread, left, begadd;
2N/A int grpx[LABMAX];
2N/A
2N/A /* compute starting coords for each group */
2N/A grpx[0] = 0;
2N/A if (_ngroups > 1) {
2N/A /* spacing between groups */
2N/A for (i = 0, n = 0; i < _ngroups; ++i)
2N/A n += _groups[i] * (len + 1) - 1;
2N/A if ((spread = (COLS - (n + 1))/(_ngroups - 1)) <= 0)
2N/A return (ERR);
2N/A left = (COLS-(n + 1)) % (_ngroups - 1);
2N/A begadd = (_ngroups / 2) - (left / 2);
2N/A
2N/A /* coords of groups */
2N/A for (i = 1; i < _ngroups; ++i) {
2N/A grpx[i] = grpx[i - 1] + (_groups[i - 1] *
2N/A (len + 1) - 1) + spread;
2N/A if (left > 0 && i > begadd) {
2N/A grpx[i]++;
2N/A left--;
2N/A }
2N/A }
2N/A }
2N/A
2N/A /* now set coords of each label */
2N/A n = 0;
2N/A for (i = 0; i < _ngroups; ++i)
2N/A for (k = 0; k < _groups[i]; ++k)
2N/A labx[n++] = grpx[i] + k * (len + 1);
2N/A return (OK);
2N/A}