author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:11 +0200 | |
changeset 32 | 9b56360ec64e |
parent 27 | 81a574d60c15 |
child 45 | 7197576fedcf |
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; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
40 |
|
0 | 41 |
char dest[4]; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
42 |
|
0 | 43 |
int maxx; |
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
44 |
|
0 | 45 |
int maxy; |
46 |
||
47 |
while (guess != ESCAPE) { |
|
48 |
while ((get_wch (&guess)) != OK) |
|
49 |
/* |
|
50 |
* waiting for multibyte character |
|
51 |
*/ |
|
52 |
; |
|
53 |
||
54 |
maxx = getmaxx (win); |
|
55 |
maxy = getmaxy (win); |
|
56 |
||
57 |
dest[0] = 0; |
|
58 |
dest[1] = 0; |
|
59 |
dest[2] = 0; |
|
60 |
dest[3] = 0; |
|
61 |
if (wctomb (dest, guess) == -1) { |
|
62 |
perror ("WCTOMB"); |
|
63 |
return -1; |
|
64 |
} |
|
65 |
||
66 |
mvprintw (maxy / 2, maxx / 2 - 12, |
|
67 |
"UTF-8: (%2X:%2X:%2X:%2X)\t\t", (u_char) dest[0], |
|
68 |
(u_char) dest[1], (u_char) dest[2], (u_char) dest[3]); |
|
69 |
||
70 |
mvprintw (maxy - 1, 0, "KEY: %2lc\t", guess); |
|
71 |
mvprintw (maxy - 1, maxx - 14, "UNICODE: %4X", guess); |
|
72 |
mvprintw (maxy - 1, maxx / 2 - 10, "Press ESC to quit"); |
|
73 |
} |
|
74 |
return guess; |
|
75 |
} |
|
76 |
||
77 |
int main () |
|
78 |
{ |
|
79 |
wchar_t x; |
|
27
81a574d60c15
typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
80 |
|
0 | 81 |
WINDOW *win; |
82 |
||
83 |
check_locale (); |
|
84 |
win = initscr (); |
|
85 |
noecho (); |
|
86 |
x = fucnt (win); |
|
87 |
endwin (); |
|
88 |
||
89 |
printf ("\n"); |
|
8
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
90 |
|
96d16dfe787a
We use return EXIT_SUCCESS instead of return 0
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
91 |
return EXIT_SUCCESS; |
0 | 92 |
} |