/* Automatically generated by
	SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.1950 uuid: b4089b49-1494-49d2-8966-57cba5c92194
   from
	ClipboardExtendedPlugin VMMaker.oscog-eem.1950 uuid: b4089b49-1494-49d2-8966-57cba5c92194
 */
static char __buildInfo[] = "ClipboardExtendedPlugin VMMaker.oscog-eem.1950 uuid: b4089b49-1494-49d2-8966-57cba5c92194 " __DATE__ ;



#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* Default EXPORT macro that does nothing (see comment in sq.h): */
#define EXPORT(returnType) returnType

/* Do not include the entire sq.h file but just those parts needed. */
#include "sqConfig.h"			/* Configuration options */
#include "sqVirtualMachine.h"	/*  The virtual machine proxy definition */
#include "sqPlatformSpecific.h"	/* Platform specific definitions */

#define true 1
#define false 0
#define null 0  /* using 'null' because nil is predefined in Think C */
#ifdef SQUEAK_BUILTIN_PLUGIN
# undef EXPORT
# define EXPORT(returnType) static returnType
#endif

#include "sqMemoryAccess.h"


/*** Function Prototypes ***/
EXPORT(const char*) getModuleName(void);
EXPORT(sqInt) ioAddClipboardData(void);
EXPORT(sqInt) ioClearClipboard(void);
EXPORT(sqInt) ioCreateClipboard(void);
EXPORT(sqInt) ioGetClipboardFormat(void);
EXPORT(sqInt) ioReadClipboardData(void);
static sqInt positiveMachineIntegerFor(unsigned long value);
EXPORT(sqInt) setInterpreter(struct VirtualMachine*anInterpreter);
static sqInt sqAssert(sqInt aBool);


/*** Variables ***/

#if !defined(SQUEAK_BUILTIN_PLUGIN)
static sqInt (*failed)(void);
static void * (*firstIndexableField)(sqInt oop);
static sqInt (*isBytes)(sqInt oop);
static sqInt (*nilObject)(void);
static sqInt (*pop)(sqInt nItems);
static sqInt (*popthenPush)(sqInt nItems, sqInt oop);
static sqInt (*positive32BitIntegerFor)(unsigned int integerValue);
static sqInt (*positive64BitIntegerFor)(usqLong integerValue);
static unsigned long (*positiveMachineIntegerValueOf)(sqInt oop);
static sqInt (*slotSizeOf)(sqInt oop);
static sqInt (*stackIntegerValue)(sqInt offset);
static sqInt (*stackValue)(sqInt offset);
static sqInt (*success)(sqInt aBoolean);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
extern sqInt failed(void);
extern void * firstIndexableField(sqInt oop);
extern sqInt isBytes(sqInt oop);
extern sqInt nilObject(void);
extern sqInt pop(sqInt nItems);
extern sqInt popthenPush(sqInt nItems, sqInt oop);
extern sqInt positive32BitIntegerFor(unsigned int integerValue);
extern sqInt positive64BitIntegerFor(usqLong integerValue);
extern unsigned long positiveMachineIntegerValueOf(sqInt oop);
extern sqInt slotSizeOf(sqInt oop);
extern sqInt stackIntegerValue(sqInt offset);
extern sqInt stackValue(sqInt offset);
extern sqInt success(sqInt aBoolean);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName =
#ifdef SQUEAK_BUILTIN_PLUGIN
	"ClipboardExtendedPlugin VMMaker.oscog-eem.1950 (i)"
#else
	"ClipboardExtendedPlugin VMMaker.oscog-eem.1950 (e)"
#endif
;



/*	Note: This is hardcoded so it can be run from Squeak.
	The module name is used for validating a module *after*
	it is loaded to check if it does really contain the module
	we're thinking it contains. This is important! */

	/* InterpreterPlugin>>#getModuleName */
EXPORT(const char*)
getModuleName(void)
{
	return moduleName;
}

	/* ClipboardExtendedPlugin>>#ioAddClipboardData:data:dataFormat: */
EXPORT(sqInt)
ioAddClipboardData(void)
{
	char *aFormat;
	sqInt clipboard;
	unsigned long clipboardAddress;
	char *data;
	sqInt dataLength;
	sqInt formatLength;

	clipboard = stackValue(2);
	success(isBytes(stackValue(1)));
	data = ((char *) (firstIndexableField(stackValue(1))));
	success(isBytes(stackValue(0)));
	aFormat = ((char *) (firstIndexableField(stackValue(0))));
	if (failed()) {
		return null;
	}
	clipboardAddress = positiveMachineIntegerValueOf(clipboard);
	dataLength = slotSizeOf(((sqInt)(long)(data) - BaseHeaderSize));
	formatLength = slotSizeOf(((sqInt)(long)(aFormat) - BaseHeaderSize));
	sqPasteboardPutItemFlavordatalengthformatTypeformatLength(clipboardAddress, data, dataLength, aFormat, formatLength);
	if (failed()) {
		return null;
	}
	pop(3);
	return null;
}

	/* ClipboardExtendedPlugin>>#ioClearClipboard: */
EXPORT(sqInt)
ioClearClipboard(void)
{
	sqInt clipboard;
	unsigned long clipboardAddress;

	clipboard = stackValue(0);
	if (failed()) {
		return null;
	}
	clipboardAddress = positiveMachineIntegerValueOf(clipboard);
	sqPasteboardClear(clipboardAddress);
	if (failed()) {
		return null;
	}
	pop(1);
	return null;
}

	/* ClipboardExtendedPlugin>>#ioCreateClipboard */
EXPORT(sqInt)
ioCreateClipboard(void)
{
	sqInt clipboardAddress;
	unsigned long value;

	/* begin positiveMachineIntegerFor: */
	value = sqCreateClipboard();
	clipboardAddress = (BytesPerWord == 8
		? positive64BitIntegerFor(value)
		: positive32BitIntegerFor(value));
	if (failed()) {
		return null;
	}
	popthenPush(1, clipboardAddress);
	return null;
}

	/* ClipboardExtendedPlugin>>#ioGetClipboardFormat:formatNumber: */
EXPORT(sqInt)
ioGetClipboardFormat(void)
{
	sqInt clipboard;
	unsigned long clipboardAddress;
	sqInt formatNumber;
	sqInt itemCount;
	sqInt _return_value;

	clipboard = stackValue(1);
	formatNumber = stackIntegerValue(0);
	if (failed()) {
		return null;
	}
	clipboardAddress = positiveMachineIntegerValueOf(clipboard);
	itemCount = sqPasteboardGetItemCount(clipboardAddress);
	if (itemCount > 0) {
if (failed()) {
			return null;
		}
		_return_value = sqPasteboardCopyItemFlavorsitemNumber(clipboardAddress, formatNumber);
		if (failed()) {
			return null;
		}
		popthenPush(3, _return_value);
		return null;
	}
	if (failed()) {
		return null;
	}
	_return_value = nilObject();
	if (failed()) {
		return null;
	}
	popthenPush(3, _return_value);
	return null;
}

	/* ClipboardExtendedPlugin>>#ioReadClipboardData:format: */
EXPORT(sqInt)
ioReadClipboardData(void)
{
	sqInt clipboard;
	unsigned long clipboardAddress;
	char *format;
	sqInt formatLength;
	sqInt _return_value;

	clipboard = stackValue(1);
	success(isBytes(stackValue(0)));
	format = ((char *) (firstIndexableField(stackValue(0))));
	if (failed()) {
		return null;
	}
	clipboardAddress = positiveMachineIntegerValueOf(clipboard);
	formatLength = slotSizeOf(((sqInt)(long)(format) - BaseHeaderSize));
	if (failed()) {
		return null;
	}
	_return_value = sqPasteboardCopyItemFlavorDataformatformatLength(clipboardAddress, format, formatLength);
	if (failed()) {
		return null;
	}
	popthenPush(3, _return_value);
	return null;
}

	/* InterpreterPlugin>>#positiveMachineIntegerFor: */
static sqInt
positiveMachineIntegerFor(unsigned long value)
{
	return (BytesPerWord == 8
		? positive64BitIntegerFor(value)
		: positive32BitIntegerFor(value));
}


/*	Note: This is coded so that it can be run in Squeak. */

	/* InterpreterPlugin>>#setInterpreter: */
EXPORT(sqInt)
setInterpreter(struct VirtualMachine*anInterpreter)
{
	sqInt ok;

	interpreterProxy = anInterpreter;
	ok = ((interpreterProxy->majorVersion()) == (VM_PROXY_MAJOR))
	 && ((interpreterProxy->minorVersion()) >= (VM_PROXY_MINOR));
	if (ok) {

#if !defined(SQUEAK_BUILTIN_PLUGIN)
		failed = interpreterProxy->failed;
		firstIndexableField = interpreterProxy->firstIndexableField;
		isBytes = interpreterProxy->isBytes;
		nilObject = interpreterProxy->nilObject;
		pop = interpreterProxy->pop;
		popthenPush = interpreterProxy->popthenPush;
		positive32BitIntegerFor = interpreterProxy->positive32BitIntegerFor;
		positive64BitIntegerFor = interpreterProxy->positive64BitIntegerFor;
		positiveMachineIntegerValueOf = interpreterProxy->positiveMachineIntegerValueOf;
		slotSizeOf = interpreterProxy->slotSizeOf;
		stackIntegerValue = interpreterProxy->stackIntegerValue;
		stackValue = interpreterProxy->stackValue;
		success = interpreterProxy->success;
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
	}
	return ok;
}

	/* SmartSyntaxInterpreterPlugin>>#sqAssert: */
static sqInt
sqAssert(sqInt aBool)
{
	/* missing DebugCode */;
	return aBool;
}


#ifdef SQUEAK_BUILTIN_PLUGIN

static char _m[] = "ClipboardExtendedPlugin";
void* ClipboardExtendedPlugin_exports[][3] = {
	{(void*)_m, "getModuleName", (void*)getModuleName},
	{(void*)_m, "ioAddClipboardData\000\000", (void*)ioAddClipboardData},
	{(void*)_m, "ioClearClipboard\000\000", (void*)ioClearClipboard},
	{(void*)_m, "ioCreateClipboard\000\377", (void*)ioCreateClipboard},
	{(void*)_m, "ioGetClipboardFormat\000\000", (void*)ioGetClipboardFormat},
	{(void*)_m, "ioReadClipboardData\000\000", (void*)ioReadClipboardData},
	{(void*)_m, "setInterpreter", (void*)setInterpreter},
	{NULL, NULL, NULL}
};

#else /* ifdef SQ_BUILTIN_PLUGIN */

signed char ioAddClipboardDataAccessorDepth = 0;
signed char ioClearClipboardAccessorDepth = 0;
signed char ioGetClipboardFormatAccessorDepth = 0;
signed char ioReadClipboardDataAccessorDepth = 0;

#endif /* ifdef SQ_BUILTIN_PLUGIN */
