drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / os2 / pdcclip.c
blob1922bb83f050752f319a443561e65d79a9c53259
1 /* Public Domain Curses */
3 #include "pdcos2.h"
5 RCSID("$Id: pdcclip.c,v 1.33 2008/07/14 04:24:51 wmcbrine Exp $")
7 /*man-start**************************************************************
9 Name: clipboard
11 Synopsis:
12 int PDC_getclipboard(char **contents, long *length);
13 int PDC_setclipboard(const char *contents, long length);
14 int PDC_freeclipboard(char *contents);
15 int PDC_clearclipboard(void);
17 Description:
18 PDC_getclipboard() gets the textual contents of the system's
19 clipboard. This function returns the contents of the clipboard
20 in the contents argument. It is the responsibilitiy of the
21 caller to free the memory returned, via PDC_freeclipboard().
22 The length of the clipboard contents is returned in the length
23 argument.
25 PDC_setclipboard copies the supplied text into the system's
26 clipboard, emptying the clipboard prior to the copy.
28 PDC_clearclipboard() clears the internal clipboard.
30 Return Values:
31 indicator of success/failure of call.
32 PDC_CLIP_SUCCESS the call was successful
33 PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
34 the clipboard contents
35 PDC_CLIP_EMPTY the clipboard contains no text
36 PDC_CLIP_ACCESS_ERROR no clipboard support
38 Portability X/Open BSD SYS V
39 PDC_getclipboard - - -
40 PDC_setclipboard - - -
41 PDC_freeclipboard - - -
42 PDC_clearclipboard - - -
44 **man-end****************************************************************/
46 int PDC_getclipboard(char **contents, long *length)
48 #ifndef EMXVIDEO
49 HMQ hmq;
50 HAB hab;
51 PTIB ptib;
52 PPIB ppib;
53 ULONG ulRet;
54 long len;
55 int rc;
56 #endif
57 PDC_LOG(("PDC_getclipboard() - called\n"));
59 #ifndef EMXVIDEO
60 DosGetInfoBlocks(&ptib, &ppib);
61 ppib->pib_ultype = 3;
62 hab = WinInitialize(0);
63 hmq = WinCreateMsgQueue(hab, 0);
65 if (!WinOpenClipbrd(hab))
67 WinDestroyMsgQueue(hmq);
68 WinTerminate(hab);
69 return PDC_CLIP_ACCESS_ERROR;
72 rc = PDC_CLIP_EMPTY;
74 ulRet = WinQueryClipbrdData(hab, CF_TEXT);
76 if (ulRet)
78 len = strlen((char *)ulRet);
79 *contents = malloc(len + 1);
81 if (!*contents)
82 rc = PDC_CLIP_MEMORY_ERROR;
83 else
85 strcpy((char *)*contents, (char *)ulRet);
86 *length = len;
87 rc = PDC_CLIP_SUCCESS;
91 WinCloseClipbrd(hab);
92 WinDestroyMsgQueue(hmq);
93 WinTerminate(hab);
95 return rc;
96 #else
97 return PDC_CLIP_ACCESS_ERROR;
98 #endif
101 int PDC_setclipboard(const char *contents, long length)
103 #ifndef EMXVIDEO
104 HAB hab;
105 PTIB ptib;
106 PPIB ppib;
107 ULONG ulRC;
108 PSZ szTextOut = NULL;
109 int rc;
110 #endif
111 PDC_LOG(("PDC_setclipboard() - called\n"));
113 #ifndef EMXVIDEO
114 DosGetInfoBlocks(&ptib, &ppib);
115 ppib->pib_ultype = 3;
116 hab = WinInitialize(0);
118 if (!WinOpenClipbrd(hab))
120 WinTerminate(hab);
121 return PDC_CLIP_ACCESS_ERROR;
124 rc = PDC_CLIP_MEMORY_ERROR;
126 ulRC = DosAllocSharedMem((PVOID)&szTextOut, NULL, length + 1,
127 PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
129 if (ulRC == 0)
131 strcpy(szTextOut, contents);
132 WinEmptyClipbrd(hab);
134 if (WinSetClipbrdData(hab, (ULONG)szTextOut, CF_TEXT, CFI_POINTER))
135 rc = PDC_CLIP_SUCCESS;
136 else
138 DosFreeMem(szTextOut);
139 rc = PDC_CLIP_ACCESS_ERROR;
143 WinCloseClipbrd(hab);
144 WinTerminate(hab);
146 return rc;
147 #else
148 return PDC_CLIP_ACCESS_ERROR;
149 #endif
152 int PDC_freeclipboard(char *contents)
154 PDC_LOG(("PDC_freeclipboard() - called\n"));
156 if (contents)
157 free(contents);
159 return PDC_CLIP_SUCCESS;
162 int PDC_clearclipboard(void)
164 #ifndef EMXVIDEO
165 HAB hab;
166 PTIB ptib;
167 PPIB ppib;
168 #endif
169 PDC_LOG(("PDC_clearclipboard() - called\n"));
171 #ifndef EMXVIDEO
172 DosGetInfoBlocks(&ptib, &ppib);
173 ppib->pib_ultype = 3;
174 hab = WinInitialize(0);
176 WinEmptyClipbrd(hab);
178 WinCloseClipbrd(hab);
179 WinTerminate(hab);
181 return PDC_CLIP_SUCCESS;
182 #else
183 return PDC_CLIP_ACCESS_ERROR;
184 #endif