author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Sat, 13 Dec 2008 17:58:11 +0100 | |
changeset 19 | 933d86c1ff71 |
parent 9 | c3fecc82ade6 |
child 27 | 81a574d60c15 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
2 |
* test/demos/ncurses.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
8
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 4 |
* |
5 |
* Unicode != UTF-8 |
|
6 |
* unicode with ncursesw ( wide char) |
|
7 |
* gcc $< -lncursesw -o $@ |
|
8 |
*/ |
|
9 |
||
10 |
#include <stdio.h> |
|
11 |
#include <string.h> |
|
12 |
#include <stdlib.h> |
|
13 |
#include <fcntl.h> |
|
14 |
#include <ncursesw/curses.h> |
|
15 |
#include <wchar.h> |
|
16 |
#include <locale.h> |
|
17 |
||
18 |
#ifndef u_char |
|
19 |
typedef unsigned char u_char; |
|
20 |
#endif |
|
21 |
||
22 |
#define ESCAPE 0x1B |
|
23 |
||
24 |
#ifndef get_wch |
|
25 |
extern int get_wch (); |
|
26 |
#endif |
|
27 |
||
28 |
int check_locale () |
|
29 |
{ |
|
30 |
if (!setlocale (LC_CTYPE, "")) { |
|
31 |
perror ("SETLOCALE"); |
|
32 |
return EXIT_FAILURE; |
|
33 |
} |
|
34 |
return EXIT_SUCCESS; |
|
35 |
} |
|
36 |
||
37 |
wchar_t fucnt (WINDOW * win) |
|
38 |
{ |
|
39 |
wchar_t guess; |
|
40 |
char dest[4]; |
|
41 |
int maxx; |
|
42 |
int maxy; |
|
43 |
||
44 |
while (guess != ESCAPE) { |
|
45 |
while ((get_wch (&guess)) != OK) |
|
46 |
/* |
|
47 |
* waiting for multibyte character |
|
48 |
*/ |
|
49 |
; |
|
50 |
||
51 |
maxx = getmaxx (win); |
|
52 |
maxy = getmaxy (win); |
|
53 |
||
54 |
dest[0] = 0; |
|
55 |
dest[1] = 0; |
|
56 |
dest[2] = 0; |
|
57 |
dest[3] = 0; |
|
58 |
if (wctomb (dest, guess) == -1) { |
|
59 |
perror ("WCTOMB"); |
|
60 |
return -1; |
|
61 |
} |
|
62 |
||
63 |
mvprintw (maxy / 2, maxx / 2 - 12, |
|
64 |
"UTF-8: (%2X:%2X:%2X:%2X)\t\t", (u_char) dest[0], |
|
65 |
(u_char) dest[1], (u_char) dest[2], (u_char) dest[3]); |
|
66 |
||
67 |
mvprintw (maxy - 1, 0, "KEY: %2lc\t", guess); |
|
68 |
mvprintw (maxy - 1, maxx - 14, "UNICODE: %4X", guess); |
|
69 |
mvprintw (maxy - 1, maxx / 2 - 10, "Press ESC to quit"); |
|
70 |
} |
|
71 |
return guess; |
|
72 |
} |
|
73 |
||
74 |
int main () |
|
75 |
{ |
|
76 |
wchar_t x; |
|
77 |
WINDOW *win; |
|
78 |
||
79 |
check_locale (); |
|
80 |
win = initscr (); |
|
81 |
noecho (); |
|
82 |
x = fucnt (win); |
|
83 |
endwin (); |
|
84 |
||
85 |
printf ("\n"); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
86 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
87 |
return EXIT_SUCCESS; |
0 | 88 |
} |