//
//	Xanthus
//	Copyright (c) 1992, 1993, 1994 Xanthus International AB.  
//	All rights reserved. 
//


#import <strings.h>
#import <appkit/nextstd.h>

#import "XQ_UserFunction.h"


@interface demo2:XQ_UserFunction
@end




@implementation demo2

+ (const char *)functionName;
{
	return "demo2";
}

+ (const char *)categoryName;
{
	return "external_demos";
}

- (const char *)argumentNameNo:(int)index;
{
	switch(index) {
	case 0 : 
		return "string";
	}
	
	return "<should never be seen>";
}

- (int)minArg;				// not used in Questor 1.0
{
	return 1;
}

- (int)maxArg;				// not used in Questor 1.0
{
	return 1;
}

- (int)formalCount;
{
	return 1;
}

- (int)argType:(int)index;		// not used in Questor 1.0
{
	switch(index) {
	case 0 : 
		return XQ_EVAL;
	}
	return XQ_EVAL;
}

- (void *)runFunction: (void *)frame;
{
	char *string, *result;
	int stringType;
	int i, k = 0;
	int size = 0;
	
	stringType = XQ_ArgType(frame, 0);
	
	if(stringType != XQ_STRING_ARG)
		XQ_RaiseArgTypeError(frame, 0, XQ_STRING_ARG);
	
	string = XQ_GetStringValue(frame, 0);
	if(string == NULL) 
		return XQ_CreateStringValue(frame, "");
		
	size = strlen(string);
	NX_MALLOC(result, char, size+1);
	for(i=size-1; i>=0; i--)
		result[k++] = string[i];
	result[k] = '\0';
	
	return XQ_CreateStringValueNoMalloc(frame, result);
}

@end
