aboutsummaryrefslogtreecommitdiff
path: root/scripts/kconfig/libcurses/pdcclip.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scripts/kconfig/libcurses/pdcclip.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/scripts/kconfig/libcurses/pdcclip.c b/scripts/kconfig/libcurses/pdcclip.c
new file mode 100644
index 000000000..6184ad2d9
--- /dev/null
+++ b/scripts/kconfig/libcurses/pdcclip.c
@@ -0,0 +1,155 @@
1/* PDCurses */
2
3#include "pdcwin.h"
4
5#include <string.h>
6
7/*man-start**************************************************************
8
9clipboard
10---------
11
12### Synopsis
13
14 int PDC_getclipboard(char **contents, long *length);
15 int PDC_setclipboard(const char *contents, long length);
16 int PDC_freeclipboard(char *contents);
17 int PDC_clearclipboard(void);
18
19### Description
20
21 PDC_getclipboard() gets the textual contents of the system's
22 clipboard. This function returns the contents of the clipboard in the
23 contents argument. It is the responsibility of the caller to free the
24 memory returned, via PDC_freeclipboard(). The length of the clipboard
25 contents is returned in the length argument.
26
27 PDC_setclipboard() copies the supplied text into the system's
28 clipboard, emptying the clipboard prior to the copy.
29
30 PDC_clearclipboard() clears the internal clipboard.
31
32### Return Values
33
34 PDC_CLIP_SUCCESS the call was successful
35 PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
36 the clipboard contents
37 PDC_CLIP_EMPTY the clipboard contains no text
38 PDC_CLIP_ACCESS_ERROR no clipboard support
39
40### Portability
41
42 Function | X/Open | ncurses | NetBSD
43 :---------------------|:------:|:-------:|:------:
44 PDC_getclipboard | - | - | -
45 PDC_setclipboard | - | - | -
46 PDC_freeclipboard | - | - | -
47 PDC_clearclipboard | - | - | -
48
49**man-end****************************************************************/
50
51#ifdef PDC_WIDE
52# define PDC_TEXT CF_UNICODETEXT
53#else
54# define PDC_TEXT CF_OEMTEXT
55#endif
56
57int PDC_getclipboard(char **contents, long *length)
58{
59 HANDLE handle;
60 long len;
61
62 PDC_LOG(("PDC_getclipboard() - called\n"));
63
64 if (!OpenClipboard(NULL))
65 return PDC_CLIP_ACCESS_ERROR;
66
67 if ((handle = GetClipboardData(PDC_TEXT)) == NULL)
68 {
69 CloseClipboard();
70 return PDC_CLIP_EMPTY;
71 }
72
73#ifdef PDC_WIDE
74 len = wcslen((wchar_t *)handle) * 3;
75#else
76 len = strlen((char *)handle);
77#endif
78 *contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1);
79
80 if (!*contents)
81 {
82 CloseClipboard();
83 return PDC_CLIP_MEMORY_ERROR;
84 }
85
86#ifdef PDC_WIDE
87 len = PDC_wcstombs((char *)*contents, (wchar_t *)handle, len);
88#else
89 strcpy((char *)*contents, (char *)handle);
90#endif
91 *length = len;
92 CloseClipboard();
93
94 return PDC_CLIP_SUCCESS;
95}
96
97int PDC_setclipboard(const char *contents, long length)
98{
99 HGLOBAL ptr1;
100 LPTSTR ptr2;
101
102 PDC_LOG(("PDC_setclipboard() - called\n"));
103
104 if (!OpenClipboard(NULL))
105 return PDC_CLIP_ACCESS_ERROR;
106
107 ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
108 (length + 1) * sizeof(TCHAR));
109
110 if (!ptr1)
111 return PDC_CLIP_MEMORY_ERROR;
112
113 ptr2 = GlobalLock(ptr1);
114
115#ifdef PDC_WIDE
116 PDC_mbstowcs((wchar_t *)ptr2, contents, length);
117#else
118 memcpy((char *)ptr2, contents, length + 1);
119#endif
120 GlobalUnlock(ptr1);
121 EmptyClipboard();
122
123 if (!SetClipboardData(PDC_TEXT, ptr1))
124 {
125 GlobalFree(ptr1);
126 return PDC_CLIP_ACCESS_ERROR;
127 }
128
129 CloseClipboard();
130 GlobalFree(ptr1);
131
132 return PDC_CLIP_SUCCESS;
133}
134
135int PDC_freeclipboard(char *contents)
136{
137 PDC_LOG(("PDC_freeclipboard() - called\n"));
138
139 GlobalFree(contents);
140 return PDC_CLIP_SUCCESS;
141}
142
143int PDC_clearclipboard(void)
144{
145 PDC_LOG(("PDC_clearclipboard() - called\n"));
146
147 if (OpenClipboard(NULL))
148 if (EmptyClipboard())
149 {
150 CloseClipboard();
151 return PDC_CLIP_SUCCESS;
152 }
153
154 return PDC_CLIP_ACCESS_ERROR;
155}