Ejemplo n.º 1
0
/*
 * This creates a new CDK screen.
 */
CDKSCREEN *initCDKScreen (WINDOW *window)
{
   ALL_SCREENS *item;
   CDKSCREEN *screen = 0;

   /* initialization, for the first time */
   if (all_screens == 0)
   {
      /* Set up basic curses settings. */
#ifdef HAVE_SETLOCALE
      setlocale (LC_ALL, "");
#endif
      noecho ();
      cbreak ();
   }

   if ((item = typeMalloc (ALL_SCREENS)) != 0)
   {
      if ((screen = typeCalloc (CDKSCREEN)) != 0)
      {
	 item->link = all_screens;
	 item->screen = screen;
	 all_screens = item;

	 /* Initialize the CDKSCREEN pointer. */
	 screen->objectCount = 0;
	 screen->objectLimit = 2;
	 screen->object = typeMallocN (CDKOBJS *, screen->objectLimit);
	 screen->window = window;

	 /* OK, we are done. */
      }
      else
      {
Ejemplo n.º 2
0
NCURSES_SP_NAME(newpad) (NCURSES_SP_DCLx int l, int c)
{
    WINDOW *win;
    NCURSES_CH_T *ptr;
    int i;

    T((T_CALLED("newpad(%p,%d, %d)"), (void *) SP_PARM, l, c));

    if (l <= 0 || c <= 0)
	returnWin(0);

    win = NCURSES_SP_NAME(_nc_makenew) (NCURSES_SP_ARGx l, c, 0, 0, _ISPAD);
    if (win == NULL)
	returnWin(0);

    for (i = 0; i < l; i++) {
	if_USE_SCROLL_HINTS(win->_line[i].oldindex = _NEWINDEX);
	if ((win->_line[i].text = typeCalloc(NCURSES_CH_T, ((size_t) c))) == 0) {
	    (void) _nc_freewin(win);
	    returnWin(0);
	}
	for (ptr = win->_line[i].text; ptr < win->_line[i].text + c; ptr++)
	    SetChar(*ptr, BLANK_TEXT, BLANK_ATTR);
    }

    returnWin(win);
}
Ejemplo n.º 3
0
static COUNTS *
chrcount(char *path)
{
    char temp[1024];
    char leaf[1024];
    size_t used = 0;
    size_t need = 2;
    COUNTS *result = typeCalloc(need, COUNTS);

    if (isdirectory(path)) {
	FILE *pp = popen("ls -1 -a", "r");
	if (pp != 0) {
	    while (fgets(leaf, sizeof(leaf), pp) != 0) {
		trim(leaf);
		sprintf(temp, "%s/%s", path, leaf);
		if ((used + 1) >= need) {
		    need = (used + 1) * 2;
		    result = realloc(result, sizeof(COUNTS) * need);
		}
		if ((result[used].count = do_count(temp)) >= 0) {
		    result[used].name = strmalloc(leaf);
		    used++;
		    result[used].name = 0;
		}
	    }
	    pclose(pp);
	}
    } else {
	result[0].name = strmalloc(path);
	result[0].count = do_count(path);
    }
    return result;
}
Ejemplo n.º 4
0
_nc_acs_map(void)
{
    static chtype *the_map = 0;
    if (the_map == 0)
	the_map = typeCalloc(chtype, ACS_LEN);
    return the_map;
}
Ejemplo n.º 5
0
static CARD *
add_title(const char *title)
{
    CARD *card, *p, *q;

    for (p = all_cards, q = 0; p != 0; q = p, p = p->link) {
	int cmp = strcmp(p->title, title);
	if (cmp == 0)
	    return p;
	if (cmp > 0)
	    break;
    }

    card = typeCalloc(CARD, 1);
    card->title = strdup(title);
    card->content = strdup("");

    if (q == 0) {
	card->link = all_cards;
	all_cards = card;
    } else {
	card->link = q->link;
	q->link = card;
    }

    return card;
}
Ejemplo n.º 6
0
static TTY *
saved_tty(NCURSES_SP_DCL0)
{
    TTY *result = 0;

    if (SP_PARM != 0) {
	result = (TTY *) & (SP_PARM->_saved_tty);
    } else {
	if (_nc_prescreen.saved_tty == 0) {
	    _nc_prescreen.saved_tty = typeCalloc(TTY, 1);
	}
	result = _nc_prescreen.saved_tty;
    }
    return result;
}
Ejemplo n.º 7
0
/*
 * Define each field with an extra one, for reflecting "actual" text.
 */
static FIELD *
make_field(int frow, int fcol, int rows, int cols)
{
    FIELD *f = new_field(rows, cols, frow, fcol, o_value, 1);

    if (f) {
	FieldAttrs *ptr;

	set_field_back(f, A_UNDERLINE);
	/*
	 * If -j and -d options are combined, -j loses.  It is documented in
	 * "Character User Interface Programming", page 12-15 that setting
	 * O_STATIC off makes the form library ignore justification.
	 */
	set_field_just(f, j_value);
	if (d_option) {
	    if (has_colors()) {
		set_field_fore(f, (chtype) COLOR_PAIR(2));
		set_field_back(f, A_UNDERLINE | COLOR_PAIR(3));
	    } else {
		set_field_fore(f, A_BOLD);
	    }
	    /*
	     * The field_opts_off() call dumps core with Solaris curses,
	     * but that is a known bug in Solaris' form library -TD
	     */
	    field_opts_off(f, O_STATIC);
	    set_max_field(f, m_value);
	}

	/*
	 * The userptr is used in edit_field.c's inactive_field().
	 */
	ptr = (FieldAttrs *) field_userptr(f);
	if (ptr == 0) {
	    ptr = typeCalloc(FieldAttrs, 1);
	    ptr->background = field_back(f);
	}
	set_field_userptr(f, (void *) ptr);
	if (t_value)
	    set_field_buffer(f, 0, t_value);
    }
    return (f);
}
Ejemplo n.º 8
0
static MYDATA *
initialize(const char *name, FILE *output)
{
    MYDATA *result = typeCalloc(MYDATA, 1);
    int error;

    result->fp = output;
    result->name = name;
    result->outc = (fileno(output) == 1) ? my_outc : my_errc;
    result->sp = opt_n ? NULL : new_prescr();

    if (opt_t) {
	char *temp = strdup(name);
	tgetent_sp(result->sp, temp, name);
	free(temp);
    } else {
	setupterm((NCURSES_CONST char *) name, fileno(output), &error);
    }
    result->term = cur_term;

    return result;
}
Ejemplo n.º 9
0
/*
 * Create a new object beginning with a CDKOBJS struct.  The whole object is
 * initialized to zeroes except for special cases which have known values.
 */
void *_newCDKObject (unsigned size, const CDKFUNCS * funcs)
{
   ALL_OBJECTS *item;
   CDKOBJS *result = 0;
   if ((item = typeCalloc (ALL_OBJECTS)) != 0)
   {
      if ((result = (CDKOBJS *)calloc (1, size)) != 0)
      {
	 result->fn = funcs;
	 result->hasFocus = TRUE;
	 result->isVisible = TRUE;

	 item->link = all_objects;
	 item->object = result;
	 all_objects = item;

	 /* set default line-drawing characters */
	 result->ULChar = ACS_ULCORNER;
	 result->URChar = ACS_URCORNER;
	 result->LLChar = ACS_LLCORNER;
	 result->LRChar = ACS_LRCORNER;
	 result->HZChar = ACS_HLINE;
	 result->VTChar = ACS_VLINE;
	 result->BXAttr = A_NORMAL;

	 /* set default exit-types */
	 result->exitType = vNEVER_ACTIVATED;
	 result->earlyExit = vNEVER_ACTIVATED;
      }
      else
      {
	 free (item);
      }
   }
   return (void *)result;
}
Ejemplo n.º 10
0
_nc_add_to_try(TRIES ** tree, const char *str, unsigned code)
{
    TRIES *ptr, *savedptr;
    unsigned const char *txt = (unsigned const char *) str;

    T((T_CALLED("_nc_add_to_try(%p, %s, %u)"), *tree, _nc_visbuf(str), code));
    if (txt == 0 || *txt == '\0' || code == 0)
	returnCode(ERR);

    if ((*tree) != 0) {
	ptr = savedptr = (*tree);

	for (;;) {
	    unsigned char cmp = *txt;

	    while (!CMP_TRY(ptr->ch, cmp)
		   && ptr->sibling != 0)
		ptr = ptr->sibling;

	    if (CMP_TRY(ptr->ch, cmp)) {
		if (*(++txt) == '\0') {
		    ptr->value = code;
		    returnCode(OK);
		}
		if (ptr->child != 0)
		    ptr = ptr->child;
		else
		    break;
	    } else {
		if ((ptr->sibling = typeCalloc(TRIES, 1)) == 0) {
		    returnCode(ERR);
		}

		savedptr = ptr = ptr->sibling;
		SET_TRY(ptr, txt);
		ptr->value = 0;

		break;
	    }
	}			/* end for (;;) */
    } else {			/* (*tree) == 0 :: First sequence to be added */
	savedptr = ptr = (*tree) = typeCalloc(TRIES, 1);

	if (ptr == 0) {
	    returnCode(ERR);
	}

	SET_TRY(ptr, txt);
	ptr->value = 0;
    }

    /* at this point, we are adding to the try.  ptr->child == 0 */

    while (*txt) {
	ptr->child = typeCalloc(TRIES, 1);

	ptr = ptr->child;

	if (ptr == 0) {
	    while ((ptr = savedptr) != 0) {
		savedptr = ptr->child;
		free(ptr);
	    }
	    returnCode(ERR);
	}

	SET_TRY(ptr, txt);
	ptr->value = 0;
    }

    ptr->value = code;
    returnCode(OK);
}
Ejemplo n.º 11
0
NCURSES_PUBLIC_VAR(acs_map) (void)
{
    if (MyBuffer == 0)
	MyBuffer = typeCalloc(chtype, ACS_LEN);
    return MyBuffer;
}
Ejemplo n.º 12
0
_nc_init_wacs(void)
{
    /* *INDENT-OFF* */
    static const struct {
	int	map;
	int	value[2];
    } table[] = {
	/* VT100 symbols */
	{ 'l',	{ '+',	0x250c }},	/* upper left corner */
	{ 'm',	{ '+',	0x2514 }},	/* lower left corner */
	{ 'k',	{ '+',	0x2510 }},	/* upper right corner */
	{ 'j',	{ '+',	0x2518 }},	/* lower right corner */
	{ 't',	{ '+',	0x251c }},	/* tee pointing left */
	{ 'u',	{ '+',	0x2524 }},	/* tee pointing right */
	{ 'v',	{ '+',	0x2534 }},	/* tee pointing up */
	{ 'w',	{ '+',	0x252c }},	/* tee pointing down */
	{ 'q',	{ '-',	0x2500 }},	/* horizontal line */
	{ 'x',	{ '|',	0x2502 }},	/* vertical line */
	{ 'n',	{ '+',	0x253c }},	/* large plus or crossover */
	{ 'o',	{ '~',	0x23ba }},	/* scan line 1 */
	{ 's',	{ '_',	0x23bd }},	/* scan line 9 */
	{ '`',	{ '+',	0x25c6 }},	/* diamond */
	{ 'a',	{ ':',	0x2592 }},	/* checker board (stipple) */
	{ 'f',	{ '\'',	0x00b0 }},	/* degree symbol */
	{ 'g',	{ '#',	0x00b1 }},	/* plus/minus */
	{ '~',	{ 'o',	0x00b7 }},	/* bullet */
	/* Teletype 5410v1 symbols */
	{ ',',	{ '<',	0x2190 }},	/* arrow pointing left */
	{ '+',	{ '>',	0x2192 }},	/* arrow pointing right */
	{ '.',	{ 'v',	0x2193 }},	/* arrow pointing down */
	{ '-',	{ '^',	0x2191 }},	/* arrow pointing up */
	{ 'h',	{ '#',	0x2592 }},	/* board of squares */
	{ 'i',	{ '#',	0x2603 }},	/* lantern symbol */
	{ '0',	{ '#',	0x25ae }},	/* solid square block */
	/* these defaults were invented for ncurses */
	{ 'p',	{ '-',	0x23bb }},	/* scan line 3 */
	{ 'r',	{ '-',	0x23bc }},	/* scan line 7 */
	{ 'y',	{ '<',	0x2264 }},	/* less-than-or-equal-to */
	{ 'z',	{ '>',	0x2265 }},	/* greater-than-or-equal-to */
	{ '{',	{ '*',	0x03c0 }},	/* greek pi */
	{ '|',	{ '!',	0x2260 }},	/* not-equal */
	{ '}',	{ 'f',	0x00a3 }},	/* pound-sterling symbol */
    };
    /* *INDENT-ON* */

    unsigned n, m;
    int active = _nc_unicode_locale();

    /*
     * If we're running in a UTF-8 locale, will use the Unicode equivalents
     * rather than the terminfo information.  Actually the terminfo should
     * be the rule, but there are people who are offended by the notion that
     * a Unicode-capable terminal would have something resembling a mode.
     * So the smacs/rmacs may be disabled -- sometime.
     */
    T(("initializing WIDE-ACS map (Unicode is%s active)",
       active ? "" : " not"));

    _nc_wacs = typeCalloc(cchar_t, ACS_LEN);
    for (n = 0; n < SIZEOF(table); ++n) {
	int wide = wcwidth(table[n].value[active]);

	m = table[n].map;
	if (active && (wide == 1)) {
	    SetChar(_nc_wacs[m], table[n].value[active], A_NORMAL);
	} else if (acs_map[m] & A_ALTCHARSET) {
	    SetChar(_nc_wacs[m], m, A_ALTCHARSET);
	} else {
	    SetChar(_nc_wacs[m], table[n].value[0], A_NORMAL);
	}

	T(("#%d, SetChar(%c, %#04x) = %s",
	   n, m,
	   table[n].value[active],
	   _tracecchar_t(&_nc_wacs[m])));
    }
}
Ejemplo n.º 13
0
#if HAVE_USE_WINDOW
    SCREEN *sp GCC_UNUSED,
#endif
    void *arg)
{
    DITTO *target = (DITTO *) arg;
    int high, wide;
    int k;

    cbreak();
    noecho();
    scrollok(stdscr, TRUE);
    box(stdscr, 0, 0);

    target->windows = typeCalloc(WINDOW *, (size_t) target->length);
    target->peeks = typeCalloc(PEEK, (size_t) target->length);

    high = (LINES - 2) / target->length;
    wide = (COLS - 2);
    for (k = 0; k < target->length; ++k) {
        WINDOW *outer = newwin(high, wide, 1 + (high * k), 1);
        WINDOW *inner = derwin(outer, high - 2, wide - 2, 1, 1);

        box(outer, 0, 0);
        mvwaddstr(outer, 0, 2, target->titles[k]);
        wnoutrefresh(outer);

        scrollok(inner, TRUE);
        keypad(inner, TRUE);
#ifndef USE_PTHREADS
        nodelay(inner, TRUE);
Ejemplo n.º 14
0
_nc_alloc_screen(void)
{
    return ((my_screen = typeCalloc(SCREEN, 1)) != 0);
}
Ejemplo n.º 15
0
_nc_acs_map(void)
{
    if (MyBuffer == 0)
	MyBuffer = typeCalloc(chtype, ACS_LEN);
    return MyBuffer;
}
Ejemplo n.º 16
0
/*
 * Initialize soft labels.
 * Called from newterm()
 */
int
_nc_slk_initialize(WINDOW *stwin, int cols)
{
int i, x;
char *p;

	T(("slk_initialize()"));

	if (SP->_slk)
	  { /* we did this already, so simply return */
	    return(OK);
	  }
	else
	  if ((SP->_slk = typeCalloc(SLK, 1)) == 0)
	    return(ERR);

	SP->_slk->ent    = NULL;
	SP->_slk->buffer = NULL;
	SP->_slk->attr   = A_STANDOUT;

#ifdef num_labels
	SP->_slk->maxlab = (num_labels > 0) ? num_labels : MAX_SKEY;
	SP->_slk->maxlen = (num_labels > 0) ? label_width * label_height : MAX_SKEY_LEN;
	SP->_slk->labcnt = (SP->_slk->maxlab < MAX_SKEY) ? MAX_SKEY : SP->_slk->maxlab;
#else
	SP->_slk->labcnt = SP->_slk->maxlab = MAX_SKEY;
	SP->_slk->maxlen = MAX_SKEY_LEN;
#endif /* num_labels */

	SP->_slk->ent = typeCalloc(slk_ent, SP->_slk->labcnt);
	if (SP->_slk->ent == NULL)
	  goto exception;

	p = SP->_slk->buffer = (char*) calloc(2*SP->_slk->labcnt,(1+SP->_slk->maxlen));
	if (SP->_slk->buffer == NULL)
	  goto exception;

	for (i = 0; i < SP->_slk->labcnt; i++) {
		SP->_slk->ent[i].text = p;
		p += (1 + SP->_slk->maxlen);
		SP->_slk->ent[i].form_text = p;
		p += (1 + SP->_slk->maxlen);
		memset(SP->_slk->ent[i].form_text, ' ', (unsigned)(SP->_slk->maxlen));
		SP->_slk->ent[i].visible = (i < SP->_slk->maxlab);
	}
	if (_nc_slk_format >= 3) /* PC style */
	  {
	    int gap = (cols - 3 * (3 + 4*SP->_slk->maxlen))/2;

	    if (gap < 1)
	      gap = 1;

	    for (i = x = 0; i < SP->_slk->maxlab; i++) {
	      SP->_slk->ent[i].x = x;
	      x += SP->_slk->maxlen;
	      x += (i==3 || i==7) ? gap : 1;
	    }
	    if (_nc_slk_format == 4)
	      slk_paint_info (stwin);
	  }
	else {
	  if (_nc_slk_format == 2) {	/* 4-4 */
	    int gap = cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 6;

	    if (gap < 1)
			gap = 1;
	    for (i = x = 0; i < SP->_slk->maxlab; i++) {
	      SP->_slk->ent[i].x = x;
	      x += SP->_slk->maxlen;
	      x += (i == 3) ? gap : 1;
	    }
	  }
	  else
	    {
	      if (_nc_slk_format == 1) { /* 1 -> 3-2-3 */
		int gap = (cols - (SP->_slk->maxlab * SP->_slk->maxlen) - 5) / 2;

		if (gap < 1)
		  gap = 1;
		for (i = x = 0; i < SP->_slk->maxlab; i++) {
		  SP->_slk->ent[i].x = x;
		  x += SP->_slk->maxlen;
		  x += (i == 2 || i == 4) ? gap : 1;
		}
	      }
	      else
		goto exception;
	    }
	}
	SP->_slk->dirty = TRUE;
	if ((SP->_slk->win = stwin) == NULL)
	{
	exception:
		if (SP->_slk)
		{
		   FreeIfNeeded(SP->_slk->buffer);
		   FreeIfNeeded(SP->_slk->ent);
		   free(SP->_slk);
		   SP->_slk = (SLK*)0;
		   return(ERR);
		}
	}

	return(OK);
}
Ejemplo n.º 17
0
int
main(int argc, char **argv)
{
    struct name_table_entry *name_table = typeCalloc(struct
						     name_table_entry, CAPTABSIZE);
    HashValue *hash_table = typeCalloc(HashValue, HASHTABSIZE);
    const char *root_name = "";
    int column = 0;
    int bigstring = 0;
    int n;
    char buffer[BUFSIZ];

    static const char *typenames[] =
    {"BOOLEAN", "NUMBER", "STRING"};

    short BoolCount = 0;
    short NumCount = 0;
    short StrCount = 0;

    /* The first argument is the column-number (starting with 0).
     * The second is the root name of the tables to generate.
     */
    if (argc <= 3
	|| (column = atoi(argv[1])) <= 0
	|| (column >= MAX_COLUMNS)
	|| *(root_name = argv[2]) == 0
	|| (bigstring = atoi(argv[3])) < 0
	|| name_table == 0
	|| hash_table == 0) {
	fprintf(stderr, "usage: make_hash column root_name bigstring\n");
	exit(EXIT_FAILURE);
    }

    /*
     * Read the table into our arrays.
     */
    for (n = 0; (n < CAPTABSIZE) && fgets(buffer, BUFSIZ, stdin);) {
	char **list, *nlp = strchr(buffer, '\n');
	if (nlp)
	    *nlp = '\0';
	list = parse_columns(buffer);
	if (list == 0)		/* blank or comment */
	    continue;
	if (column > count_columns(list)) {
	    fprintf(stderr, "expected %d columns, have %d:\n%s\n",
		    column,
		    count_columns(list),
		    buffer);
	    exit(EXIT_FAILURE);
	}
	name_table[n].nte_link = -1;	/* end-of-hash */
	name_table[n].nte_name = strmalloc(list[column]);
	if (!strcmp(list[2], "bool")) {
	    name_table[n].nte_type = BOOLEAN;
	    name_table[n].nte_index = BoolCount++;
	} else if (!strcmp(list[2], "num")) {
	    name_table[n].nte_type = NUMBER;
	    name_table[n].nte_index = NumCount++;
	} else if (!strcmp(list[2], "str")) {
	    name_table[n].nte_type = STRING;
	    name_table[n].nte_index = StrCount++;
	} else {
	    fprintf(stderr, "Unknown type: %s\n", list[2]);
	    exit(EXIT_FAILURE);
	}
	n++;
    }
    _nc_make_hash_table(name_table, hash_table);

    /*
     * Write the compiled tables to standard output
     */
    if (bigstring) {
	int len = 0;
	int nxt;

	printf("static const char %s_names_text[] = \\\n", root_name);
	for (n = 0; n < CAPTABSIZE; n++) {
	    nxt = (int) strlen(name_table[n].nte_name) + 5;
	    if (nxt + len > 72) {
		printf("\\\n");
		len = 0;
	    }
	    printf("\"%s\\0\" ", name_table[n].nte_name);
	    len += nxt;
	}
	printf(";\n\n");

	len = 0;
	printf("static name_table_data const %s_names_data[] =\n",
	       root_name);
	printf("{\n");
	for (n = 0; n < CAPTABSIZE; n++) {
	    printf("\t{ %15d,\t%10s,\t%3d, %3d }%c\n",
		   len,
		   typenames[name_table[n].nte_type],
		   name_table[n].nte_index,
		   name_table[n].nte_link,
		   n < CAPTABSIZE - 1 ? ',' : ' ');
	    len += (int) strlen(name_table[n].nte_name) + 1;
	}
	printf("};\n\n");
	printf("static struct name_table_entry *_nc_%s_table = 0;\n\n", root_name);
    } else {

	printf("static struct name_table_entry const _nc_%s_table[] =\n",
	       root_name);
	printf("{\n");
	for (n = 0; n < CAPTABSIZE; n++) {
	    _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "\"%s\"",
			name_table[n].nte_name);
	    printf("\t{ %15s,\t%10s,\t%3d, %3d }%c\n",
		   buffer,
		   typenames[name_table[n].nte_type],
		   name_table[n].nte_index,
		   name_table[n].nte_link,
		   n < CAPTABSIZE - 1 ? ',' : ' ');
	}
	printf("};\n\n");
    }

    printf("static const HashValue _nc_%s_hash_table[%d] =\n",
	   root_name,
	   HASHTABSIZE + 1);
    printf("{\n");
    for (n = 0; n < HASHTABSIZE; n++) {
	printf("\t%3d,\n", hash_table[n]);
    }
    printf("\t0\t/* base-of-table */\n");
    printf("};\n\n");

    printf("#if (BOOLCOUNT!=%d)||(NUMCOUNT!=%d)||(STRCOUNT!=%d)\n",
	   BoolCount, NumCount, StrCount);
    printf("#error\t--> term.h and comp_captab.c disagree about the <--\n");
    printf("#error\t--> numbers of booleans, numbers and/or strings <--\n");
    printf("#endif\n\n");

    free(hash_table);
    return EXIT_SUCCESS;
}
Ejemplo n.º 18
0
int setupterm(const char *tname, int Filedes, int *errret)
{
struct term	*term_ptr;
int status;

	T((T_CALLED("setupterm(\"%s\",%d,%p)"), tname, Filedes, errret));

	if (tname == 0) {
		tname = getenv("TERM");
		if (tname == 0 || *tname == '\0') {
			ret_error0(-1, "TERM environment variable not set.\n");
                }
	}
	if (strlen(tname) > MAX_NAME_SIZE) {
		ret_error(-1, "TERM environment must be <= %d characters.\n",
		    MAX_NAME_SIZE);
	}

	T(("your terminal name is %s", tname));

	term_ptr = typeCalloc(TERMINAL, 1);

	if (term_ptr == 0) {
		ret_error0(-1, "Not enough memory to create terminal structure.\n") ;
        }
#if USE_DATABASE
	status = grab_entry(tname, &term_ptr->type);
#else
	status = 0;
#endif

	/* try fallback list if entry on disk */
	if (status != 1)
	{
	    const TERMTYPE	*fallback = _nc_fallback(tname);

	    if (fallback)
	    {
		memcpy(&term_ptr->type, fallback, sizeof(TERMTYPE));
		status = 1;
	    }
	}

	if (status == -1)
	{
		ret_error0(-1, "terminals database is inaccessible\n");
	}
	else if (status == 0)
	{
		ret_error(0, "'%s': unknown terminal type.\n", tname);
	}

	set_curterm(term_ptr);

	if (command_character  &&  getenv("CC"))
		do_prototype();

	strlcpy(ttytype, cur_term->type.term_names, NAMESIZE);

	/*
	 * Allow output redirection.  This is what SVr3 does.
	 * If stdout is directed to a file, screen updates go
	 * to standard error.
	 */
	if (Filedes == STDOUT_FILENO && !isatty(Filedes))
	    Filedes = STDERR_FILENO;
	cur_term->Filedes = Filedes;

	_nc_get_screensize(&LINES, &COLS);

	if (errret)
		*errret = 1;

	T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));

	if (generic_type) {
		ret_error(0, "'%s': I need something more specific.\n", tname);
	}
	if (hard_copy) {
		ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
	}
	returnCode(OK);
}
Ejemplo n.º 19
0
_nc_slk_initialize(WINDOW *stwin, int cols)
{
    int i;
    int res = OK;
    unsigned max_length;
    SCREEN *sp;
    TERMINAL *term;
    int numlab;

    T((T_CALLED("_nc_slk_initialize()")));

    assert(stwin);

    sp = _nc_screen_of(stwin);
    if (0 == sp)
	returnCode(ERR);

    term = TerminalOf(SP_PARM);
    assert(term);

    numlab = NumLabels;

    if (SP_PARM->_slk) {	/* we did this already, so simply return */
	returnCode(OK);
    } else if ((SP_PARM->_slk = typeCalloc(SLK, 1)) == 0)
	returnCode(ERR);

    if (!SP_PARM->slk_format)
	SP_PARM->slk_format = _nc_globals.slk_format;

    /*
     * If we use colors, vidputs() will suppress video attributes that conflict
     * with colors.  In that case, we're still guaranteed that "reverse" would
     * work.
     */
    if ((NoColorVideo & 1) == 0)
	SetAttr(SP_PARM->_slk->attr, A_STANDOUT);
    else
	SetAttr(SP_PARM->_slk->attr, A_REVERSE);

    SP_PARM->_slk->maxlab = ((numlab > 0)
			     ? numlab
			     : MAX_SKEY(SP_PARM->slk_format));
    SP_PARM->_slk->maxlen = ((numlab > 0)
			     ? LabelWidth * LabelHeight
			     : MAX_SKEY_LEN(SP_PARM->slk_format));
    SP_PARM->_slk->labcnt = ((SP_PARM->_slk->maxlab < MAX_SKEY(SP_PARM->slk_format))
			     ? MAX_SKEY(SP_PARM->slk_format)
			     : SP_PARM->_slk->maxlab);

    if (SP_PARM->_slk->maxlen <= 0
	|| SP_PARM->_slk->labcnt <= 0
	|| (SP_PARM->_slk->ent = typeCalloc(slk_ent,
					    (unsigned) SP_PARM->_slk->labcnt))
	== NULL)
	returnCode(slk_failed(NCURSES_SP_ARG));

    max_length = SP_PARM->_slk->maxlen;
    for (i = 0; i < SP_PARM->_slk->labcnt; i++) {
	size_t used = max_length + 1;

	SP_PARM->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used);
	if (SP_PARM->_slk->ent[i].ent_text == 0)
	    returnCode(slk_failed(NCURSES_SP_ARG));
	memset(SP_PARM->_slk->ent[i].ent_text, 0, used);

	SP_PARM->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used);
	if (SP_PARM->_slk->ent[i].form_text == 0)
	    returnCode(slk_failed(NCURSES_SP_ARG));
	memset(SP_PARM->_slk->ent[i].form_text, 0, used);

	memset(SP_PARM->_slk->ent[i].form_text, ' ', max_length);
	SP_PARM->_slk->ent[i].visible = (char) (i < SP_PARM->_slk->maxlab);
    }

    res = _nc_format_slks(NCURSES_SP_ARGx cols);

    if ((SP_PARM->_slk->win = stwin) == NULL) {
	returnCode(slk_failed(NCURSES_SP_ARG));
    }

    /* We now reset the format so that the next newterm has again
     * per default no SLK keys and may call slk_init again to
     * define a new layout. (juergen 03-Mar-1999)
     */
    _nc_globals.slk_format = 0;
    returnCode(res);
}
Ejemplo n.º 20
0
_nc_slk_initialize(WINDOW *stwin, int cols)
{
    int i, x;
    int res = OK;
    unsigned max_length;

    T((T_CALLED("_nc_slk_initialize()")));

    if (SP->_slk) {		/* we did this already, so simply return */
	returnCode(OK);
    } else if ((SP->_slk = typeCalloc(SLK, 1)) == 0)
	returnCode(ERR);

    SP->_slk->ent = NULL;

    /*
     * If we use colors, vidputs() will suppress video attributes that conflict
     * with colors.  In that case, we're still guaranteed that "reverse" would
     * work.
     */
    if ((no_color_video & 1) == 0)
	SetAttr(SP->_slk->attr, A_STANDOUT);
    else
	SetAttr(SP->_slk->attr, A_REVERSE);

    SP->_slk->maxlab = ((num_labels > 0)
			? num_labels
			: MAX_SKEY(_nc_globals.slk_format));
    SP->_slk->maxlen = ((num_labels > 0)
			? label_width * label_height
			: MAX_SKEY_LEN(_nc_globals.slk_format));
    SP->_slk->labcnt = ((SP->_slk->maxlab < MAX_SKEY(_nc_globals.slk_format))
			? MAX_SKEY(_nc_globals.slk_format)
			: SP->_slk->maxlab);

    if (SP->_slk->maxlen <= 0
	|| SP->_slk->labcnt <= 0
	|| (SP->_slk->ent = typeCalloc(slk_ent,
				       (unsigned) SP->_slk->labcnt)) == NULL)
	returnCode(slk_failed());

    max_length = SP->_slk->maxlen;
    for (i = 0; i < SP->_slk->labcnt; i++) {
	size_t used = max_length + 1;

	if ((SP->_slk->ent[i].ent_text = (char *) _nc_doalloc(0, used)) == 0)
	    returnCode(slk_failed());
	memset(SP->_slk->ent[i].ent_text, 0, used);

	if ((SP->_slk->ent[i].form_text = (char *) _nc_doalloc(0, used)) == 0)
	    returnCode(slk_failed());
	memset(SP->_slk->ent[i].form_text, 0, used);

	memset(SP->_slk->ent[i].form_text, ' ', max_length);
	SP->_slk->ent[i].visible = (char) (i < SP->_slk->maxlab);
    }
    if (_nc_globals.slk_format >= 3) {	/* PC style */
	int gap = (cols - 3 * (3 + 4 * max_length)) / 2;

	if (gap < 1)
	    gap = 1;

	for (i = x = 0; i < SP->_slk->maxlab; i++) {
	    SP->_slk->ent[i].ent_x = x;
	    x += max_length;
	    x += (i == 3 || i == 7) ? gap : 1;
	}
    } else {
	if (_nc_globals.slk_format == 2) {	/* 4-4 */
	    int gap = cols - (SP->_slk->maxlab * max_length) - 6;

	    if (gap < 1)
		gap = 1;
	    for (i = x = 0; i < SP->_slk->maxlab; i++) {
		SP->_slk->ent[i].ent_x = x;
		x += max_length;
		x += (i == 3) ? gap : 1;
	    }
	} else {
	    if (_nc_globals.slk_format == 1) {	/* 1 -> 3-2-3 */
		int gap = (cols - (SP->_slk->maxlab * max_length) - 5)
		/ 2;

		if (gap < 1)
		    gap = 1;
		for (i = x = 0; i < SP->_slk->maxlab; i++) {
		    SP->_slk->ent[i].ent_x = x;
		    x += max_length;
		    x += (i == 2 || i == 4) ? gap : 1;
		}
	    } else
		returnCode(slk_failed());
	}
    }
    SP->_slk->dirty = TRUE;
    if ((SP->_slk->win = stwin) == NULL) {
	returnCode(slk_failed());
    }

    /* We now reset the format so that the next newterm has again
     * per default no SLK keys and may call slk_init again to
     * define a new layout. (juergen 03-Mar-1999)
     */
    SP->slk_format = _nc_globals.slk_format;
    _nc_globals.slk_format = 0;
    returnCode(res);
}
Ejemplo n.º 21
0
	"d  dump state of test arrays",
	"h  apply hash mapper and see scroll optimization",
	"?  this message"
    };
    size_t n;
    for (n = 0; n < sizeof(table)/sizeof(table[0]); n++)
	fprintf(stderr, "%s\n", table[n]);
}

int
main(int argc GCC_UNUSED, char *argv[] GCC_UNUSED)
{
    char	line[BUFSIZ], *st;
    int		n;

    SP = typeCalloc(SCREEN,1);
    for (n = 0; n < screen_lines; n++)
    {
	reallines[n] = n;
	oldnums[n] = _NEWINDEX;
	oldtext[n][0] = newtext[n][0] = '.';
    }

    if (isatty(fileno(stdin)))
	usage();

#ifdef TRACE
    _nc_tracing = TRACE_MOVE;
#endif
    for (;;)
    {