1 // $Id$
2 //
3 // Create an empty YAPET file, press Enter (nothing must happen),
4 // press 'd' (nothing must happen). Quit YAPET.
5 //
6 //
7 // call yapet like this
8 //
9 // LD_PRELOAD=libpwrecord.so yapet -i /tmp/testfile
10 #include <libyacurscfg.h>
11
12 #if defined(HAVE_CURSES_ENHANCED) && defined(HAVE_LOCALE_H) && \
13 defined(HAVE_CWCHAR) && !defined(DISABLE_WCHAR)
14 #define YACURS_USE_WCHAR 1
15 #endif
16
17 #include <unistd.h>
18 #include <cstdlib>
19
20 #ifdef YACURS_USE_WCHAR
21 #include <clocale>
22 #include <cwchar>
23 #endif
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #ifdef YACURS_USE_WCHAR
30 std::wint_t
31 #else
32 int
33 #endif
34 __test_data[50][100] = {
35 {'\n', 0},
36 // Password for new file
37 {'p', 'l', 'e', 'a', 's', 'e', 'c', 'h', 'a', 'n', 'g', 'e', '\n', 0},
38 // Enter password again
39 {'p', 'l', 'e', 'a', 's', 'e', 'c', 'h', 'a', 'n', 'g', 'e', '\n', 0},
40 {'\n', 0}, // Press ok button
41 {'\n', 0}, // must not do anything
42 {'d', 0}, // must not do anything
43 {'q', 0}, // quit
44 {0}};
45
46 #ifdef YACURS_USE_WCHAR
wget_wch(void * wdc,std::wint_t * i)47 int wget_wch(void* wdc, std::wint_t* i) {
48 static int row = 0;
49 static int col = 0;
50
51 if (__test_data[row][col] == 0) {
52 col = 0;
53 row++;
54
55 if (__test_data[row][col] == 0) std::abort();
56 }
57
58 *i = __test_data[row][col++];
59
60 return 0;
61 }
62
63 #else
wgetch(void * wdc)64 int wgetch(void* wdc) {
65 static int row = 0;
66 static int col = 0;
67
68 if (__test_data[row][col] == 0) {
69 col = 0;
70 row++;
71
72 if (__test_data[row] == 0) std::abort();
73 }
74
75 return __test_data[row][col++];
76 }
77
78 #endif
79
80 #ifdef __cplusplus
81 }
82 #endif
83