Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3316
Browse files Browse the repository at this point in the history
Bow to the inevitable and go with as traditional platforms/Cross style include
file for the ClipboardExtendedPlugin (int is not wide enough to hold an oop on
64-bits).

Harden the fetch functions on iOS and unix to check for out-of-memory.

The plugin now seems to work on unix but much work needs to be done to
platforms/unix/vm-display-x11/sqUnixX11.c because playing with e.g. firefox
shows that copying HTML text has no effect on the results passed up from
clipboardGetTypeNames et al.
  • Loading branch information
eliotmiranda committed Mar 28, 2023
1 parent ef43c43 commit 4f91346
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 98 deletions.
@@ -0,0 +1,23 @@
#ifndef _SQ_CLIPBOARD_PLUGIN_H_
#define _SQ_CLIPBOARD_PLUGIN_H_

// Platform-specific interface for the ClipboardExtendedPlugin
// If a more specific type than void * is required, define CLIPBOARDTYPE to that
// type before including this file in your platform support code.

#if !defined(CLIPBOARDTYPE)
# define CLIPBOARDTYPE void *
#endif

void sqPasteboardClear(CLIPBOARDTYPE inPasteboard);
sqInt sqPasteboardGetItemCount(CLIPBOARDTYPE inPasteboard);
sqInt sqPasteboardCopyItemFlavorsitemNumber(CLIPBOARDTYPE inPasteboard, sqInt formatNumber);
void *sqCreateClipboard(void);
void sqPasteboardPutItemFlavordatalengthformatTypeformatLength(CLIPBOARDTYPE inPasteboard, char *inData, sqInt dataLength, char *format, sqInt formatLength);
void sqPasteboardPutItemFlavordatalengthformatType(CLIPBOARDTYPE inPasteboard, char *inData, sqInt dataLength, sqInt format);
sqInt sqPasteboardCopyItemFlavorDataformatformatLength(CLIPBOARDTYPE inPasteboard, char *format, sqInt formatLength);
sqInt sqPasteboardCopyItemFlavorDataformat(CLIPBOARDTYPE inPasteboard, sqInt format);
sqInt sqPasteboardhasDataInFormatformatLength(CLIPBOARDTYPE inPasteboard, char *format, sqInt formatLength);
sqInt sqPasteboardhasDataInFormat(CLIPBOARDTYPE inPasteboard, sqInt format);

#endif // _SQ_CLIPBOARD_PLUGIN_H_

This file was deleted.

@@ -1,6 +1,5 @@
/*
* sqMacExtendedClipboard.m
* SqueakClipboardExtendedxcodeproj
*
* Created by John Sterling Mcintosh on 4/21/06.
* Copyright 2006-2010 Corporate Smalltalk Consulting ltd. All rights reserved.
Expand All @@ -25,13 +24,18 @@
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*/

#include "sqMacExtendedClipboard.h"
#include "sqVirtualMachine.h"
#ifdef BUILD_FOR_OSX
#import <Cocoa/Cocoa.h>
# define CLIPBOARDTYPE NSPasteboard *
#else
# define CLIPBOARDTYPE UIPasteboard *
#endif
#include "ClipboardExtendedPlugin.h"

extern struct VirtualMachine* interpreterProxy;
extern struct VirtualMachine *interpreterProxy;

void
sqPasteboardClear(CLIPBOARDTYPE inPasteboard)
Expand Down Expand Up @@ -60,8 +64,12 @@
const char *utf8data = [formatType UTF8String];
formatTypeLength = strlen(utf8data);
sqInt outData = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classString(), formatTypeLength);
unsigned char *formatConverted = interpreterProxy->firstIndexableField(outData);
memcpy(formatConverted,utf8data,formatTypeLength);
if (!outData)
interpreterProxy->primitiveFailFor(PrimErrNoMemory);
else {
unsigned char *formatConverted = interpreterProxy->firstIndexableField(outData);
memcpy(formatConverted,utf8data,formatTypeLength);
}

return outData;
}
Expand Down Expand Up @@ -110,9 +118,12 @@
NSData *dataBuffer = [inPasteboard dataForType: type];
sqInt dataLength = [dataBuffer length];
sqInt outData = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classByteArray(), dataLength);
char *outDataPtr = (char *) interpreterProxy->firstIndexableField(outData);
[dataBuffer getBytes: outDataPtr length: dataLength];

if (!outData) {
interpreterProxy->primitiveFailFor(PrimErrNoMemory);
return interpreterProxy->nilObject();
}
char *outDataPtr = (char *) interpreterProxy->firstIndexableField(outData);
[dataBuffer getBytes: outDataPtr length: dataLength];
return outData;
}

Expand Down
Expand Up @@ -26,6 +26,7 @@
*/

#include "sqVirtualMachine.h"
#include "ClipboardExtendedPlugin.h"
extern struct VirtualMachine *interpreterProxy;

#include <string.h>
Expand All @@ -49,12 +50,12 @@ void clipboardWriteWithType(char *data, size_t ndata, char *typeName, size_t nty
// be changed to include a pointer to the item count and then the indexing
// can safely be done directly. eem. '23/3/25

/* In X11 clipboard is global in a display, so just return 1 */
sqInt
sqCreateClipboard(void) { return 1; }
/* In X11 clipboard is global in a display, so just return a constant */
void *
sqCreateClipboard(void) { return (void *)0xB0A4D; }

void
sqPasteboardClear(sqInt inPasteboard)
sqPasteboardClear(void *inPasteboard)
{
// perhaps PrimErrUnsupported is better, but it's inaccurate
// we don't yet have PrimErrUnimplemented
Expand All @@ -67,7 +68,7 @@ sqPasteboardClear(sqInt inPasteboard)
* Update it only if the selection is CLIPBOARD
*/
int
sqPasteboardGetItemCount(sqInt inPasteboard)
sqPasteboardGetItemCount(void *inPasteboard)
{
int i;
char **types = clipboardGetTypeNames();
Expand All @@ -80,8 +81,8 @@ sqPasteboardGetItemCount(sqInt inPasteboard)
}

/* Answer a type name at index. */
int
sqPasteboardCopyItemFlavorsitemNumber(sqInt inPasteboard, sqInt formatNumber)
sqInt
sqPasteboardCopyItemFlavorsitemNumber(void *inPasteboard, sqInt formatNumber)
{
int i;
sqInt outData = 0;
Expand All @@ -93,49 +94,61 @@ sqPasteboardCopyItemFlavorsitemNumber(sqInt inPasteboard, sqInt formatNumber)
if (i + 1 == formatNumber) {
int length = strlen(types[i]);
outData = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classString(), length);

memcpy( interpreterProxy->firstIndexableField(outData),
types[i],
length);
if (!outData)
interpreterProxy->primitiveFailFor(PrimErrNoMemory);
else
memcpy( interpreterProxy->firstIndexableField(outData),
types[i],
length);
}
free(types[i]); /* XFree() is better */
}
free(types);
return outData;
return outData
? outData
: interpreterProxy->nilObject();
}

void
sqPasteboardPutItemFlavordatalengthformatTypeformatLength(sqInt inPasteboard, char *data, sqInt ndata, char *typeName, sqInt ntypeName)
sqPasteboardPutItemFlavordatalengthformatTypeformatLength(void *inPasteboard, char *data, sqInt ndata, char *typeName, sqInt ntypeName)
{
clipboardWriteWithType(data, ndata, typeName, ntypeName, 0, 1);
}


void
sqPasteboardPutItemFlavordatalengthformatType(sqInt inPasteboard, char *inData, sqInt dataLength, sqInt format)
sqPasteboardPutItemFlavordatalengthformatType(void *inPasteboard, char *inData, sqInt dataLength, sqInt format)
{
interpreterProxy->primitiveFailFor(PrimErrUnsupported);
}


/* Read the clipboard */
int
sqPasteboardCopyItemFlavorDataformatformatLength(sqInt inPasteboard, char *format, sqInt formatLength)
sqInt
sqPasteboardCopyItemFlavorDataformatformatLength(void *inPasteboard, char *format, sqInt formatLength)
{
int bytes = clipboardSizeWithType(format, formatLength);

if (!bytes)
return interpreterProxy->nilObject();

sqInt outData = interpreterProxy->instantiateClassindexableSize(interpreterProxy->classByteArray(), bytes);
if (!outData) {
interpreterProxy->primitiveFailFor(PrimErrNoMemory);
return interpreterProxy->nilObject();
}
clipboardReadIntoAt(bytes, (sqInt) firstIndexableField(outData), 0);
return outData;
}

sqPasteboardCopyItemFlavorDataformat(sqInt inPasteboard, sqInt format)
sqPasteboardCopyItemFlavorDataformat(void *inPasteboard, sqInt format)
{
interpreterProxy->primitiveFailFor(PrimErrUnsupported);
return interpreterProxy->nilObject();
}

sqInt
sqPasteboardhasDataInFormatformatLength(sqInt inPasteboard, char *format, sqInt formatLength)
sqPasteboardhasDataInFormatformatLength(void *inPasteboard, char *format, sqInt formatLength)
{
int i, found = 0;
char **types = clipboardGetTypeNames();
Expand All @@ -153,7 +166,7 @@ sqPasteboardhasDataInFormatformatLength(sqInt inPasteboard, char *format, sqInt
}

sqInt
sqPasteboardhasDataInFormat(sqInt inPasteboard, sqInt format)
sqPasteboardhasDataInFormat(void *inPasteboard, sqInt format)
{
interpreterProxy->primitiveFailFor(PrimErrUnsupported);
return interpreterProxy->nilObject();
Expand Down
Expand Up @@ -8,8 +8,11 @@
#include <Windows.h>
#include "sqWin32.h"
#include "sqVirtualMachine.h"
#include "ClipboardExtendedPlugin.h"
#include "sqAssert.h"

extern struct VirtualMachine *interpreterProxy;

// As a convenience, because UTF16/CF_UNICODETEXT is so tricky, handle
// CF_PRIVATELAST as a special code implying put/get UTF-8 converted
// to/from UTF16
Expand All @@ -24,9 +27,6 @@ __declspec(dllimport) void *getSTWindowHandle(void);
# define myWindow() getSTWindowHandle()
#endif

extern struct VirtualMachine* interpreterProxy;
typedef void *CLIPBOARDTYPE;

void
sqPasteboardClear(CLIPBOARDTYPE inPasteboard)
{
Expand Down
25 changes: 5 additions & 20 deletions src/plugins/ClipboardExtendedPlugin/ClipboardExtendedPlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3313 uuid: eec7f9f2-1dea-4660-bacc-8f63d29beb2e
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3316 uuid: 5216fdfa-1bd8-4f37-9cd1-7aba18a852db
from
ClipboardExtendedPlugin VMMaker.oscog-eem.3313 uuid: eec7f9f2-1dea-4660-bacc-8f63d29beb2e
ClipboardExtendedPlugin VMMaker.oscog-eem.3316 uuid: 5216fdfa-1bd8-4f37-9cd1-7aba18a852db
*/
static char __buildInfo[] = "ClipboardExtendedPlugin VMMaker.oscog-eem.3313 uuid: eec7f9f2-1dea-4660-bacc-8f63d29beb2e " __DATE__ ;
static char __buildInfo[] = "ClipboardExtendedPlugin VMMaker.oscog-eem.3316 uuid: 5216fdfa-1bd8-4f37-9cd1-7aba18a852db " __DATE__ ;


#include "config.h"
Expand All @@ -19,6 +19,7 @@ static char __buildInfo[] = "ClipboardExtendedPlugin VMMaker.oscog-eem.3313 uuid
#include "sqVirtualMachine.h" /* The virtual machine proxy definition */
#include "sqPlatformSpecific.h" /* Platform specific definitions */

#include "ClipboardExtendedPlugin.h"
#include "sqMemoryAccess.h"

#define true 1
Expand All @@ -33,22 +34,6 @@ static char __buildInfo[] = "ClipboardExtendedPlugin VMMaker.oscog-eem.3313 uuid
#endif


/* ClipboardExtendedPlugin class>>preambleCCode */
// declarations for the support API. eem, 10/10/2022

void sqPasteboardClear(void *inPasteboard);
sqInt sqPasteboardGetItemCount(void *inPasteboard);
sqInt sqPasteboardCopyItemFlavorsitemNumber(void *inPasteboard, sqInt formatNumber);
void *sqCreateClipboard(void);
void sqPasteboardPutItemFlavordatalengthformatTypeformatLength(void *inPasteboard, char *inData, sqInt dataLength, char *format, sqInt formatLength);
void sqPasteboardPutItemFlavordatalengthformatType(void *inPasteboard, char *inData, sqInt dataLength, sqInt format);
sqInt sqPasteboardCopyItemFlavorDataformatformatLength(void *inPasteboard, char *format, sqInt formatLength);
sqInt sqPasteboardCopyItemFlavorDataformat(void *inPasteboard, sqInt format);
sqInt sqPasteboardhasDataInFormatformatLength(void *inPasteboard, char *format, sqInt formatLength);
sqInt sqPasteboardhasDataInFormat(void *inPasteboard, sqInt format);
/* end ClipboardExtendedPlugin class>>preambleCCode */


/*** Function Prototypes ***/
EXPORT(const char*) getModuleName(void);
EXPORT(sqInt) ioAddClipboardData(void);
Expand Down Expand Up @@ -115,7 +100,7 @@ extern sqInt stackValue(sqInt offset);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "ClipboardExtendedPlugin VMMaker.oscog-eem.3313 " INT_EXT;
static const char *moduleName = "ClipboardExtendedPlugin VMMaker.oscog-eem.3316 " INT_EXT;



Expand Down

0 comments on commit 4f91346

Please sign in to comment.