1 /* $NetBSD: ex1.c,v 1.5 2007/05/28 15:01:58 blymn Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 static char copyright
[] =
35 "@(#) Copyright (c) 1992, 1993\n\
36 The Regents of the University of California. All rights reserved.\n";
40 static char sccsid
[] = "@(#)ex1.c 8.1 (Berkeley) 6/4/93";
42 #include <sys/types.h>
58 int i
, j
, c
, n
= 0, ac
= 0;
63 cchar_t cc
, ncc
, cstr
[ 128 ], icc
, icstr
[ 128 ], bcc
;
64 int wc_on
= 0, wgc_on
= 0;
66 char mbstr
[] = "´óѧ֮µÀ£¬ÔÚÃ÷Ã÷µÂ£¬ÔÚÇ×Ãñ£¬ÔÚÖ¹ÓÚÖÁÉÆ¡£ (Liji)";
67 wchar_t wstr
[ 128 ], owstr
[ 4 ], gwstr
[ 128 ], iwstr
[ 128 ];
71 attr_t al
[ 15 ] = { WA_BLINK
,
86 fprintf( stderr
, "Current locale: %s\n", setlocale(LC_ALL
, ""));
87 if (( wslen
= mbstowcs( &cc
.vals
[ 0 ], mbs
, strlen( mbs
))) < 0 ) {
88 fprintf( stderr
, "mbstowcs() failed\n" );
91 fprintf( stderr
, "WC string length: %d\n", wslen
);
92 fprintf( stderr
, "WC width: %d\n", wcwidth( cc
.vals
[ 0 ]));
93 cc
.elements
= ncc
.elements
= 8;
94 cc
.attributes
= ncc
.attributes
= 0;
95 ncc
.vals
[ 0 ] = 0xda00;
96 cc
.vals
[ 1 ] = ncc
.vals
[ 1 ] = 0xda01;
97 cc
.vals
[ 2 ] = ncc
.vals
[ 2 ] = 0xda02;
98 cc
.vals
[ 3 ] = ncc
.vals
[ 3 ] = 0xda03;
99 cc
.vals
[ 4 ] = ncc
.vals
[ 4 ] = 0xda04;
100 cc
.vals
[ 5 ] = ncc
.vals
[ 5 ] = 0xda05;
101 cc
.vals
[ 6 ] = ncc
.vals
[ 6 ] = 0xda06;
102 cc
.vals
[ 7 ] = ncc
.vals
[ 7 ] = 0xda07;
104 if (( wslen
= mbstowcs( wstr
, mbstr
, strlen( mbstr
))) < 0 ) {
105 fprintf( stderr
, "mbstowcs() failed\n" );
109 for ( i
= 0; i
< wslen
; i
++ ) {
110 cstr
[ i
].vals
[ 0 ] = wstr
[ i
];
112 cstr
[ wslen
].vals
[ 0 ] = 0;
116 bcc
.vals
[ 0 ] = L
'_';
117 bcc
.vals
[ 1 ] = 0xda01;
118 bcc
.vals
[ 2 ] = 0xda02;
119 bcc
.vals
[ 3 ] = 0xda03;
120 bcc
.vals
[ 4 ] = 0xda04;
121 bcc
.vals
[ 5 ] = 0xda05;
122 bcc
.vals
[ 6 ] = 0xda06;
123 bcc
.vals
[ 7 ] = 0xda07;
125 initscr(); /* Always call initscr() first */
126 signal(SIGINT
, quit
); /* Make sure wou have a 'cleanup' fn */
127 crmode(); /* We want cbreak mode */
128 noecho(); /* We want to have control of chars */
129 delwin(stdscr
); /* Create our own stdscr */
130 stdscr
= newwin(YSIZE
, XSIZE
, 1, 1);
131 flushok(stdscr
, TRUE
); /* Enable flushing of stdout */
132 scrollok(stdscr
, TRUE
); /* Enable scrolling */
133 erase(); /* Initially, clear the screen */
141 case 'q': /* Quit on 'q' */
145 keypad( stdscr
, TRUE
);
148 keypad( stdscr
, FALSE
);
184 hline_set( &cc
, 20 );
186 vline_set( &cc
, 20 );
193 case 's': /* Go into standout mode on 's' */
196 case 'e': /* Exit standout mode on 'e' */
199 case 'r': /* Force a refresh on 'r' */
202 case 'w': /* Turn on/off add_wch() tests */
206 add_wchstr(( const cchar_t
*)&cstr
);
210 addwstr(( const wchar_t *)&wstr
);
234 //border( 0, 0, 0, 0, 0, 0, 0, 0 );
235 border_set( NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
239 box_set( stdscr
, &cc
, &cc
);
253 sprintf( nostr
, "Orig:%x", al
[ ac
]);
255 ac
= ( ac
+ 1 ) % 16;
256 bcc
.attributes
= al
[ ac
];
259 sprintf( nostr
, "New:%x", al
[ ac
]);
272 ins_wstr(( const wchar_t *)&wstr
);
276 for ( i
= 0; i
< 4; i
++ ) {
277 owstr
[ i
] = wstr
[ i
+ 5 ];
278 wstr
[ i
+ 5 ] = i
+ 0xda05;
280 ins_wstr(( const wchar_t *)&wstr
);
282 for ( i
= 0; i
< 4; i
++ )
283 wstr
[ i
+ 5 ] = owstr
[ i
];
285 default: /* By default output the character */
292 addstr( keyname( c
));
308 notimeout( stdscr
, TRUE
);
311 notimeout( stdscr
, FALSE
);
314 nodelay( stdscr
, TRUE
);
317 nodelay( stdscr
, FALSE
);
320 keypad( stdscr
, TRUE
);
323 keypad( stdscr
, FALSE
);
334 erase(); /* Terminate by erasing the screen */
336 endwin(); /* Always end with endwin() */
337 delwin(curscr
); /* Return storage */