equal
deleted
inserted
replaced
|
1 /** |
|
2 * $Id: ncurses.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $ |
|
3 * $Source: /development/c/demos/ncurses.c,v $ |
|
4 * |
|
5 */ |
|
6 |
|
7 /* |
|
8 * Unicode != UTF-8 |
|
9 * unicode with ncursesw ( wide char) |
|
10 * gcc $< -lncursesw -o $@ |
|
11 * |
|
12 */ |
|
13 |
|
14 #include <stdio.h> |
|
15 #include <string.h> |
|
16 #include <stdlib.h> |
|
17 #include <fcntl.h> |
|
18 #include <ncursesw/curses.h> |
|
19 #include <wchar.h> |
|
20 #include <locale.h> |
|
21 |
|
22 #ifndef u_char |
|
23 typedef unsigned char u_char; |
|
24 #endif |
|
25 |
|
26 #define ESCAPE 0x1B |
|
27 |
|
28 #ifndef get_wch |
|
29 extern int get_wch (); |
|
30 #endif |
|
31 |
|
32 int check_locale () |
|
33 { |
|
34 if (!setlocale (LC_CTYPE, "")) { |
|
35 perror ("SETLOCALE"); |
|
36 return EXIT_FAILURE; |
|
37 } |
|
38 return EXIT_SUCCESS; |
|
39 } |
|
40 |
|
41 wchar_t fucnt (WINDOW * win) |
|
42 { |
|
43 wchar_t guess; |
|
44 char dest[4]; |
|
45 int maxx; |
|
46 int maxy; |
|
47 |
|
48 while (guess != ESCAPE) { |
|
49 while ((get_wch (&guess)) != OK) |
|
50 /* |
|
51 * waiting for multibyte character |
|
52 */ |
|
53 ; |
|
54 |
|
55 maxx = getmaxx (win); |
|
56 maxy = getmaxy (win); |
|
57 |
|
58 dest[0] = 0; |
|
59 dest[1] = 0; |
|
60 dest[2] = 0; |
|
61 dest[3] = 0; |
|
62 if (wctomb (dest, guess) == -1) { |
|
63 perror ("WCTOMB"); |
|
64 return -1; |
|
65 } |
|
66 |
|
67 mvprintw (maxy / 2, maxx / 2 - 12, |
|
68 "UTF-8: (%2X:%2X:%2X:%2X)\t\t", (u_char) dest[0], |
|
69 (u_char) dest[1], (u_char) dest[2], (u_char) dest[3]); |
|
70 |
|
71 mvprintw (maxy - 1, 0, "KEY: %2lc\t", guess); |
|
72 mvprintw (maxy - 1, maxx - 14, "UNICODE: %4X", guess); |
|
73 mvprintw (maxy - 1, maxx / 2 - 10, "Press ESC to quit"); |
|
74 } |
|
75 return guess; |
|
76 } |
|
77 |
|
78 int main () |
|
79 { |
|
80 wchar_t x; |
|
81 WINDOW *win; |
|
82 |
|
83 check_locale (); |
|
84 win = initscr (); |
|
85 noecho (); |
|
86 x = fucnt (win); |
|
87 endwin (); |
|
88 |
|
89 printf ("\n"); |
|
90 return 0; |
|
91 } |