Skip to content

Commit d97b6a4

Browse files
committed
Clipboard routines (pdcclip.c) for Plan9 and SDL1 were simple in-memory functions, same as the ones currently used for DOS, DOSVGA, VT, and framebuffer.
1 parent b861159 commit d97b6a4

File tree

2 files changed

+2
-198
lines changed

2 files changed

+2
-198
lines changed

plan9/pdcclip.c

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1 @@
1-
#include <stdlib.h>
2-
#include <string.h>
3-
#include <curspriv.h>
4-
#include "pdcplan9.h"
5-
6-
7-
static char *clip = NULL;
8-
9-
int PDC_getclipboard(char **sp, long *np)
10-
{
11-
long n;
12-
13-
PDC_LOG(("PDC_getclipboard() - called\n"));
14-
if (!clip)
15-
return PDC_CLIP_EMPTY;
16-
17-
n = strlen(clip);
18-
if ((*sp = malloc(n + 1)) == NULL)
19-
return PDC_CLIP_MEMORY_ERROR;
20-
21-
memmove(*sp, clip, n);
22-
*np = n;
23-
24-
return PDC_CLIP_SUCCESS;
25-
}
26-
27-
28-
int PDC_setclipboard(const char *s, long n)
29-
{
30-
PDC_LOG(("PDC_setclipboard() - called\n"));
31-
if (clip)
32-
{
33-
free(clip);
34-
clip = NULL;
35-
}
36-
if (s)
37-
{
38-
if ((clip = malloc(n + 1)) == NULL)
39-
return PDC_CLIP_MEMORY_ERROR;
40-
memmove(clip, s, n);
41-
clip[n] = 0;
42-
}
43-
44-
return PDC_CLIP_SUCCESS;
45-
}
46-
47-
48-
int PDC_freeclipboard(char *s)
49-
{
50-
PDC_LOG(("PDC_freeclipboard() - called\n"));
51-
free(s);
52-
53-
return PDC_CLIP_SUCCESS;
54-
}
55-
56-
57-
int PDC_clearclipboard(void)
58-
{
59-
PDC_LOG(("PDC_clearclipboard() - called\n"));
60-
if (clip)
61-
{
62-
free(clip);
63-
clip = NULL;
64-
}
65-
66-
return PDC_CLIP_SUCCESS;
67-
}
1+
#include "../common/pdcclip.c"

sdl1/pdcclip.c

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1 @@
1-
/* PDCurses */
2-
3-
#include "pdcsdl.h"
4-
5-
#include <stdlib.h>
6-
#include <string.h>
7-
8-
/*man-start**************************************************************
9-
10-
clipboard
11-
---------
12-
13-
### Synopsis
14-
15-
int PDC_getclipboard(char **contents, long *length);
16-
int PDC_setclipboard(const char *contents, long length);
17-
int PDC_freeclipboard(char *contents);
18-
int PDC_clearclipboard(void);
19-
20-
### Description
21-
22-
PDC_getclipboard() gets the textual contents of the system's
23-
clipboard. This function returns the contents of the clipboard in the
24-
contents argument. It is the responsibility of the caller to free the
25-
memory returned, via PDC_freeclipboard(). The length of the clipboard
26-
contents is returned in the length argument.
27-
28-
PDC_setclipboard copies the supplied text into the system's
29-
clipboard, emptying the clipboard prior to the copy.
30-
31-
PDC_clearclipboard() clears the internal clipboard.
32-
33-
### Return Values
34-
35-
indicator of success/failure of call.
36-
PDC_CLIP_SUCCESS the call was successful
37-
PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
38-
the clipboard contents
39-
PDC_CLIP_EMPTY the clipboard contains no text
40-
PDC_CLIP_ACCESS_ERROR no clipboard support
41-
42-
### Portability
43-
X/Open ncurses NetBSD
44-
PDC_getclipboard - - -
45-
PDC_setclipboard - - -
46-
PDC_freeclipboard - - -
47-
PDC_clearclipboard - - -
48-
49-
**man-end****************************************************************/
50-
51-
/* global clipboard contents, should be NULL if none set */
52-
53-
static char *pdc_SDL_clipboard = NULL;
54-
55-
int PDC_getclipboard(char **contents, long *length)
56-
{
57-
int len;
58-
59-
PDC_LOG(("PDC_getclipboard() - called\n"));
60-
61-
if (!pdc_SDL_clipboard)
62-
return PDC_CLIP_EMPTY;
63-
64-
len = strlen(pdc_SDL_clipboard);
65-
if ((*contents = malloc(len + 1)) == NULL)
66-
return PDC_CLIP_MEMORY_ERROR;
67-
68-
strcpy(*contents, pdc_SDL_clipboard);
69-
*length = len;
70-
71-
return PDC_CLIP_SUCCESS;
72-
}
73-
74-
int PDC_setclipboard(const char *contents, long length)
75-
{
76-
PDC_LOG(("PDC_setclipboard() - called\n"));
77-
78-
if (pdc_SDL_clipboard)
79-
{
80-
free(pdc_SDL_clipboard);
81-
pdc_SDL_clipboard = NULL;
82-
}
83-
84-
if (contents)
85-
{
86-
if ((pdc_SDL_clipboard = malloc(length + 1)) == NULL)
87-
return PDC_CLIP_MEMORY_ERROR;
88-
89-
strcpy(pdc_SDL_clipboard, contents);
90-
}
91-
92-
return PDC_CLIP_SUCCESS;
93-
}
94-
95-
int PDC_freeclipboard(char *contents)
96-
{
97-
PDC_LOG(("PDC_freeclipboard() - called\n"));
98-
99-
/* should we also free empty the system clipboard? probably not */
100-
101-
if (contents)
102-
{
103-
/* NOTE: We free the memory, but we can not set caller's pointer
104-
to NULL, so if caller calls again then will try to access
105-
free'd memory. We 1st overwrite memory with a string so if
106-
caller tries to use free memory they won't get what they
107-
expect & hopefully notice. */
108-
109-
/* memset(contents, 0xFD, strlen(contents)); */
110-
111-
if (strlen(contents) >= strlen("PDCURSES"))
112-
strcpy(contents, "PDCURSES");
113-
114-
free(contents);
115-
}
116-
117-
return PDC_CLIP_SUCCESS;
118-
}
119-
120-
int PDC_clearclipboard(void)
121-
{
122-
PDC_LOG(("PDC_clearclipboard() - called\n"));
123-
124-
if (pdc_SDL_clipboard)
125-
{
126-
free(pdc_SDL_clipboard);
127-
pdc_SDL_clipboard = NULL;
128-
}
129-
130-
return PDC_CLIP_SUCCESS;
131-
}
1+
#include "../common/pdcclip.c"

0 commit comments

Comments
 (0)