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

« back to all changes in this revision

Viewing changes to ncurses/trace/visbuf.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) 2001-2004,2005 Free Software Foundation, Inc.              *
 
2
 * Copyright (c) 2001-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            *
36
36
 *      visbuf.c - Tracing/Debugging support routines
37
37
 */
38
38
 
 
39
#define NEED_NCURSES_CH_T
39
40
#include <curses.priv.h>
40
41
 
41
42
#include <tic.h>
42
43
#include <ctype.h>
43
44
 
44
 
MODULE_ID("$Id: visbuf.c,v 1.14 2005/08/20 20:01:20 tom Exp $")
 
45
MODULE_ID("$Id: visbuf.c,v 1.21 2006/12/02 21:20:28 tom Exp $")
 
46
 
 
47
static const char d_quote[] = {D_QUOTE, 0};
 
48
static const char l_brace[] = {L_BRACE, 0};
 
49
static const char r_brace[] = {R_BRACE, 0};
45
50
 
46
51
static char *
47
52
_nc_vischar(char *tp, unsigned c)
126
131
    return _nc_visbuf2n(0, buf, len);
127
132
}
128
133
 
 
134
#ifdef TRACE
129
135
#if USE_WIDEC_SUPPORT
130
 
#ifdef TRACE
131
136
 
132
137
#if defined(USE_TERMLIB)
133
138
#define _nc_wchstrlen _my_wchstrlen
173
178
            j = strlen(temp);
174
179
        }
175
180
        for (k = 0; k < j; ++k) {
176
 
            tp = _nc_vischar(tp, temp[k]);
 
181
            tp = _nc_vischar(tp, UChar(temp[k]));
177
182
        }
178
183
    }
179
184
    *tp++ = D_QUOTE;
220
225
 
221
226
    return _nc_viswbuf2(0, mybuf);
222
227
}
 
228
#endif /* USE_WIDEC_SUPPORT */
223
229
 
 
230
/* use these functions for displaying parts of a line within a window */
224
231
NCURSES_EXPORT(const char *)
225
 
_nc_viscbuf2(int bufnum, const cchar_t *buf, int len)
 
232
_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
226
233
{
227
234
    char *result = _nc_trace_buf(bufnum, BUFSIZ);
228
 
    int n;
229
 
    bool same = TRUE;
230
 
    attr_t attr = A_NORMAL;
 
235
    int first;
231
236
    const char *found;
232
237
 
 
238
#if USE_WIDEC_SUPPORT
233
239
    if (len < 0)
234
240
        len = _nc_wchstrlen(buf);
235
 
 
236
 
    for (n = 1; n < len; n++) {
237
 
        if (!SameAttrOf(buf[n], buf[0])) {
238
 
            same = FALSE;
239
 
            break;
240
 
        }
241
 
    }
 
241
#endif /* USE_WIDEC_SUPPORT */
242
242
 
243
243
    /*
244
 
     * If the rendition is the same for the whole string, display it as a
245
 
     * quoted string, followed by the rendition.  Otherwise, use the more
246
 
     * detailed trace function that displays each character separately.
 
244
     * Display one or more strings followed by attributes.
247
245
     */
248
 
    if (same) {
249
 
        static const char d_quote[] =
250
 
        {D_QUOTE, 0};
251
 
 
 
246
    first = 0;
 
247
    while (first < len) {
 
248
        attr_t attr = AttrOf(buf[first]);
 
249
        int last = len - 1;
 
250
        int j;
 
251
 
 
252
        for (j = first + 1; j < len; ++j) {
 
253
            if (!SameAttrOf(buf[j], buf[first])) {
 
254
                last = j - 1;
 
255
                break;
 
256
            }
 
257
        }
 
258
 
 
259
        result = _nc_trace_bufcat(bufnum, l_brace);
252
260
        result = _nc_trace_bufcat(bufnum, d_quote);
253
 
        while (len-- > 0) {
254
 
            if ((found = _nc_altcharset_name(attr, CharOfD(buf))) != 0) {
 
261
        for (j = first; j <= last; ++j) {
 
262
            if ((found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j]))) != 0) {
255
263
                result = _nc_trace_bufcat(bufnum, found);
256
264
                attr &= ~A_ALTCHARSET;
257
 
            } else if (!isWidecExt(CHDEREF(buf))) {
 
265
            } else
 
266
#if USE_WIDEC_SUPPORT
 
267
            if (!isWidecExt(buf[j])) {
258
268
                PUTC_DATA;
259
269
 
260
270
                PUTC_INIT;
261
 
                do {
262
 
                    PUTC_ch = PUTC_i < CCHARW_MAX ? buf->chars[PUTC_i] : L'\0';
263
 
                    PUTC_n = wcrtomb(PUTC_buf, buf->chars[PUTC_i], &PUT_st);
 
271
                for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
 
272
                    int k;
 
273
 
 
274
                    PUTC_ch = buf[j].chars[PUTC_i];
264
275
                    if (PUTC_ch == L'\0')
265
 
                        --PUTC_n;
 
276
                        break;
 
277
                    PUTC_n = wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st);
266
278
                    if (PUTC_n <= 0)
267
279
                        break;
268
 
                    for (n = 0; n < PUTC_n; n++) {
 
280
                    for (k = 0; k < PUTC_n; k++) {
269
281
                        char temp[80];
270
 
                        _nc_vischar(temp, UChar(PUTC_buf[n]));
 
282
                        _nc_vischar(temp, UChar(PUTC_buf[k]));
271
283
                        result = _nc_trace_bufcat(bufnum, temp);
272
284
                    }
273
 
                    ++PUTC_i;
274
 
                } while (PUTC_ch != L'\0');
275
 
            }
276
 
            buf++;
 
285
                }
 
286
            }
 
287
#else
 
288
            {
 
289
                char temp[80];
 
290
                _nc_vischar(temp, UChar(buf[j]));
 
291
                result = _nc_trace_bufcat(bufnum, temp);
 
292
            }
 
293
#endif /* USE_WIDEC_SUPPORT */
277
294
        }
278
295
        result = _nc_trace_bufcat(bufnum, d_quote);
279
296
        if (attr != A_NORMAL) {
280
297
            result = _nc_trace_bufcat(bufnum, " | ");
281
298
            result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
282
299
        }
283
 
    } else {
284
 
        static const char l_brace[] =
285
 
        {L_BRACE, 0};
286
 
        static const char r_brace[] =
287
 
        {R_BRACE, 0};
288
 
        strcpy(result, l_brace);
289
 
        while (len-- > 0) {
290
 
            result = _nc_trace_bufcat(bufnum,
291
 
                                      _tracecchar_t2(bufnum + 20, buf++));
292
 
        }
293
300
        result = _nc_trace_bufcat(bufnum, r_brace);
 
301
        first = last + 1;
294
302
    }
295
303
    return result;
296
304
}
297
305
 
298
306
NCURSES_EXPORT(const char *)
299
 
_nc_viscbuf(const cchar_t *buf, int len)
 
307
_nc_viscbuf(const NCURSES_CH_T * buf, int len)
300
308
{
301
309
    return _nc_viscbuf2(0, buf, len);
302
310
}
303
311
#endif /* TRACE */
304
 
#endif /* USE_WIDEC_SUPPORT */