~ubuntu-branches/ubuntu/natty/ncurses/natty

« back to all changes in this revision

Viewing changes to ncurses/tinfo/lib_setup.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-05-17 09:00:42 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517090042-86fgxrr6j5jzagot
Tags: 5.6-0ubuntu1
* New upstream version.
  - Remove patches applied upstream: ncurses.upstream, signed-chars.
  - Update patches: debian-backspace.
* Build-depend on g++-multilib instead of lib{32,64}c*-dev-*.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
 
 * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
 
2
 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
3
3
 *                                                                          *
4
4
 * Permission is hereby granted, free of charge, to any person obtaining a  *
5
5
 * copy of this software and associated documentation files (the            *
53
53
 
54
54
#include <term.h>               /* lines, columns, cur_term */
55
55
 
56
 
MODULE_ID("$Id: lib_setup.c,v 1.88 2005/03/12 19:41:45 tom Exp $")
 
56
MODULE_ID("$Id: lib_setup.c,v 1.95 2006/07/28 22:58:13 tom Exp $")
57
57
 
58
58
/****************************************************************************
59
59
 *
106
106
 
107
107
static int _use_env = TRUE;
108
108
 
 
109
#if USE_SIGWINCH
 
110
int
 
111
_nc_handle_sigwinch(int enable)
 
112
{
 
113
    static int have_sigwinch = 0;       /* initially no SIGWINCH's */
 
114
    static int can_resizeall = 1;       /* initially enabled */
 
115
    SCREEN *scan;
 
116
    int result;
 
117
 
 
118
    switch (enable) {
 
119
    default:
 
120
        /* record a SIGWINCH */
 
121
        have_sigwinch = 1;
 
122
        break;
 
123
    case 0:
 
124
        /* temporarily disable the next block */
 
125
        --can_resizeall;
 
126
        break;
 
127
    case 1:
 
128
        /* temporarily enable the next block */
 
129
        ++can_resizeall;
 
130
        break;
 
131
    }
 
132
 
 
133
    /*
 
134
     * If we have a pending SIGWINCH, set the flag in each screen.
 
135
     * But do this only if the block is enabled.
 
136
     */
 
137
    if (can_resizeall-- >= 0) { /* test and disable */
 
138
        if (have_sigwinch) {
 
139
            scan = _nc_screen_chain;
 
140
            while (scan) {
 
141
                scan->_sig_winch = TRUE;
 
142
                scan = scan->_next_screen;
 
143
            }
 
144
            have_sigwinch = 0;
 
145
        }
 
146
    }
 
147
    result = can_resizeall + 1; /* reenable (unless disables are nested) */
 
148
    can_resizeall = result;
 
149
 
 
150
    return result;
 
151
}
 
152
 
 
153
#endif
 
154
 
109
155
NCURSES_EXPORT(void)
110
156
use_env(bool f)
111
157
{
121
167
    /* figure out the size of the screen */
122
168
    T(("screen size: terminfo lines = %d columns = %d", lines, columns));
123
169
 
 
170
    _nc_handle_sigwinch(0);
124
171
    if (!_use_env) {
125
172
        *linep = (int) lines;
126
173
        *colp = (int) columns;
167
214
                 * environment variable.
168
215
                 */
169
216
                if (*linep <= 0)
170
 
                    *linep = WINSIZE_ROWS(size);
 
217
                    *linep = (SP != 0 && SP->_filtered) ? 1 : WINSIZE_ROWS(size);
171
218
                if (*colp <= 0)
172
219
                    *colp = WINSIZE_COLS(size);
173
220
            }
199
246
        lines = (short) (*linep);
200
247
        columns = (short) (*colp);
201
248
    }
 
249
    _nc_handle_sigwinch(1);
202
250
 
203
251
    T(("screen size is %dx%d", *linep, *colp));
204
252
 
257
305
                                        }
258
306
 
259
307
#if USE_DATABASE || USE_TERMCAP
 
308
/*
 
309
 * Return 1 if entry found, 0 if not found, -1 if database not accessible,
 
310
 * just like tgetent().
 
311
 */
260
312
static int
261
313
grab_entry(const char *const tn, TERMTYPE *const tp)
262
 
/* return 1 if entry found, 0 if not found, -1 if database not accessible */
263
314
{
264
 
#if USE_DATABASE
265
315
    char filename[PATH_MAX];
266
 
#endif
267
 
    int status;
268
 
 
269
 
    /*
270
 
     * $TERM shouldn't contain pathname delimiters.
271
 
     */
272
 
    if (strchr(tn, '/'))
273
 
        return 0;
274
 
 
275
 
#if USE_DATABASE
276
 
    if ((status = _nc_read_entry(tn, filename, tp)) != 1) {
277
 
 
278
 
#if !PURE_TERMINFO
279
 
        /*
280
 
         * Try falling back on the termcap file.
281
 
         * Note:  allowing this call links the entire terminfo/termcap
282
 
         * compiler into the startup code.  It's preferable to build a
283
 
         * real terminfo database and use that.
284
 
         */
285
 
        status = _nc_read_termcap_entry(tn, tp);
286
 
#endif /* PURE_TERMINFO */
287
 
 
288
 
    }
289
 
#else
290
 
    status = _nc_read_termcap_entry(tn, tp);
291
 
#endif
 
316
    int status = _nc_read_entry(tn, filename, tp);
292
317
 
293
318
    /*
294
319
     * If we have an entry, force all of the cancelled strings to null
296
321
     * (The terminfo compiler bypasses this logic, since it must know if
297
322
     * a string is cancelled, for merging entries).
298
323
     */
299
 
    if (status == 1) {
 
324
    if (status == TGETENT_YES) {
300
325
        unsigned n;
301
326
        for_each_boolean(n, tp) {
302
327
            if (!VALID_BOOLEAN(tp->Booleans[n]))
316
341
**
317
342
**      Take the real command character out of the CC environment variable
318
343
**      and substitute it in for the prototype given in 'command_character'.
319
 
**
320
344
*/
321
345
static void
322
346
do_prototype(void)
417
441
}
418
442
 
419
443
/*
420
 
 * This entrypoint is called from tgetent() to allow special a case of reusing
 
444
 * This entrypoint is called from tgetent() to allow a special case of reusing
421
445
 * the same TERMINAL data (see comment).
422
446
 */
423
447
NCURSES_EXPORT(int)
431
455
    if (tname == 0) {
432
456
        tname = getenv("TERM");
433
457
        if (tname == 0 || *tname == '\0') {
434
 
            ret_error0(-1, "TERM environment variable not set.\n");
 
458
            ret_error0(TGETENT_ERR, "TERM environment variable not set.\n");
435
459
        }
436
460
    }
 
461
 
437
462
    if (strlen(tname) > MAX_NAME_SIZE) {
438
 
        ret_error(-1, "TERM environment must be <= %d characters.\n",
 
463
        ret_error(TGETENT_ERR,
 
464
                  "TERM environment must be <= %d characters.\n",
439
465
                  MAX_NAME_SIZE);
440
466
    }
441
467
 
477
503
        term_ptr = typeCalloc(TERMINAL, 1);
478
504
 
479
505
        if (term_ptr == 0) {
480
 
            ret_error0(-1,
 
506
            ret_error0(TGETENT_ERR,
481
507
                       "Not enough memory to create terminal structure.\n");
482
508
        }
483
509
#if USE_DATABASE || USE_TERMCAP
484
510
        status = grab_entry(tname, &term_ptr->type);
485
511
#else
486
 
        status = 0;
 
512
        status = TGETENT_NO;
487
513
#endif
488
514
 
489
515
        /* try fallback list if entry on disk */
490
 
        if (status != 1) {
 
516
        if (status != TGETENT_YES) {
491
517
            const TERMTYPE *fallback = _nc_fallback(tname);
492
518
 
493
519
            if (fallback) {
494
520
                term_ptr->type = *fallback;
495
 
                status = 1;
 
521
                status = TGETENT_YES;
496
522
            }
497
523
        }
498
524
 
499
 
        if (status <= 0) {
 
525
        if (status != TGETENT_YES) {
500
526
            del_curterm(term_ptr);
501
 
            if (status == -1) {
502
 
                ret_error0(-1, "terminals database is inaccessible\n");
503
 
            } else if (status == 0) {
504
 
                ret_error(0, "'%s': unknown terminal type.\n", tname);
 
527
            if (status == TGETENT_ERR) {
 
528
                ret_error0(status, "terminals database is inaccessible\n");
 
529
            } else if (status == TGETENT_NO) {
 
530
                ret_error(status, "'%s': unknown terminal type.\n", tname);
505
531
            }
506
532
        }
507
533
 
534
560
    _nc_get_screensize(&LINES, &COLS);
535
561
 
536
562
    if (errret)
537
 
        *errret = 1;
 
563
        *errret = TGETENT_YES;
538
564
 
539
565
    T((T_CREATE("screen %s %dx%d"), tname, LINES, COLS));
540
566
 
541
567
    if (generic_type) {
542
 
        ret_error(0, "'%s': I need something more specific.\n", tname);
 
568
        ret_error(TGETENT_NO, "'%s': I need something more specific.\n", tname);
543
569
    }
544
570
    if (hard_copy) {
545
 
        ret_error(1, "'%s': I can't handle hardcopy terminals.\n", tname);
 
571
        ret_error(TGETENT_YES, "'%s': I can't handle hardcopy terminals.\n", tname);
546
572
    }
547
573
    returnCode(OK);
548
574
}
552
578
 *
553
579
 *      Find and read the appropriate object file for the terminal
554
580
 *      Make cur_term point to the structure.
555
 
 *
556
581
 */
557
 
 
558
582
NCURSES_EXPORT(int)
559
583
setupterm(NCURSES_CONST char *tname, int Filedes, int *errret)
560
584
{