~ubuntu-branches/ubuntu/precise/ncurses/precise

« back to all changes in this revision

Viewing changes to ncurses/base/lib_addch.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-11 16:40:32 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081111164032-dudxd0hy2im0f2bj
Tags: 5.7-2ubuntu1
* Merge from debian unstable, remaining changes:
  - On amd64, use /{,usr/}lib32 instead of /emul/ia32-linux/.
  - Link using -Bsymbolic-functions.
  - Don't install the upstream changelog in the runtime library packages.

* Install wide-character patches into /{,usr/}lib32 as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
 
 * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
 
2
 * Copyright (c) 1998-2006,2008 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            *
36
36
#include <curses.priv.h>
37
37
#include <ctype.h>
38
38
 
39
 
MODULE_ID("$Id: lib_addch.c,v 1.104 2006/10/14 20:31:19 tom Exp $")
 
39
MODULE_ID("$Id: lib_addch.c,v 1.113 2008/08/16 19:20:04 tom Exp $")
40
40
 
41
41
static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
42
42
 
210
210
    WINDOW_EXT(win, addch_y) = y;
211
211
 
212
212
    init_mb(state);
213
 
    buffer[WINDOW_EXT(win, addch_used)] = CharOf(CHDEREF(ch));
 
213
    buffer[WINDOW_EXT(win, addch_used)] = (char) CharOf(CHDEREF(ch));
214
214
    WINDOW_EXT(win, addch_used) += 1;
215
215
    buffer[WINDOW_EXT(win, addch_used)] = '\0';
216
216
    if ((len = mbrtowc(&result,
217
217
                       buffer,
218
218
                       WINDOW_EXT(win, addch_used), &state)) > 0) {
219
219
        attr_t attrs = AttrOf(CHDEREF(ch));
 
220
        if_EXT_COLORS(int pair = GetPair(CHDEREF(ch)));
220
221
        SetChar(CHDEREF(ch), result, attrs);
221
 
        WINDOW_EXT(win, addch_used) = 0;
222
 
    } else {
223
 
        if (len == -1) {
224
 
            /*
225
 
             * An error occurred.  We could either discard everything,
226
 
             * or assume that the error was in the previous input.
227
 
             * Try the latter.
228
 
             */
229
 
            TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error"));
230
 
            buffer[0] = CharOf(CHDEREF(ch));
231
 
            WINDOW_EXT(win, addch_used) = 1;
232
 
        }
 
222
        if_EXT_COLORS(SetPair(CHDEREF(ch), pair));
 
223
        WINDOW_EXT(win, addch_used) = 0;
 
224
    } else if (len == -1) {
 
225
        /*
 
226
         * An error occurred.  We could either discard everything,
 
227
         * or assume that the error was in the previous input.
 
228
         * Try the latter.
 
229
         */
 
230
        TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error"));
 
231
        /* handle this with unctrl() */
 
232
        WINDOW_EXT(win, addch_used) = 0;
233
233
    }
234
234
    return len;
235
235
}
264
264
        if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) {
265
265
            int len = _nc_build_wch(win, CHREF(ch));
266
266
 
267
 
            if (len > 0) {
 
267
            if (len >= -1) {
 
268
                /* handle EILSEQ */
268
269
                if (is8bits(CharOf(ch))) {
269
270
                    const char *s = unctrl((chtype) CharOf(ch));
270
271
                    if (s[1] != 0) {
271
272
                        return waddstr(win, s);
272
273
                    }
273
274
                }
 
275
                if (len == -1)
 
276
                    return waddch(win, ' ');
274
277
            } else {
275
278
                return OK;
276
279
            }
287
290
        int len = wcwidth(CharOf(ch));
288
291
        int i;
289
292
        int j;
 
293
        wchar_t *chars;
290
294
 
291
295
        if (len == 0) {         /* non-spacing */
292
296
            if ((x > 0 && y >= 0)
293
 
                || ((y = win->_cury - 1) >= 0 &&
294
 
                    (x = win->_maxx) > 0)) {
295
 
                wchar_t *chars = (win->_line[y].text[x - 1].chars);
 
297
                || (win->_maxx >= 0 && win->_cury >= 1)) {
 
298
                if (x > 0 && y >= 0)
 
299
                    chars = (win->_line[y].text[x - 1].chars);
 
300
                else
 
301
                    chars = (win->_line[y - 1].text[win->_maxx].chars);
296
302
                for (i = 0; i < CCHARW_MAX; ++i) {
297
303
                    if (chars[i] == 0) {
298
304
                        TR(TRACE_VIRTPUT,
473
479
        while (*s) {
474
480
            NCURSES_CH_T sch;
475
481
            SetChar(sch, *s++, AttrOf(ch));
 
482
            if_EXT_COLORS(SetPair(sch, GetPair(ch)));
476
483
            if (waddch_literal(win, sch) == ERR)
477
484
                return ERR;
478
485
        }