/* Core Extension Library */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../basext.h"
typedef struct _ModuleObject {
void *HandleArray;
}ModuleObject,*pModuleObject;
besVERSION_NEGOTIATE
return (int)INTERFACE_VERSION;
besEND
besSUB_START
pModuleObject p;
besMODULEPOINTER = besALLOC(sizeof(ModuleObject));
if( besMODULEPOINTER == NULL )return 0;
p = (pModuleObject)besMODULEPOINTER;
return 0;
besEND
besSUB_FINISH
pModuleObject p;
p = (pModuleObject)besMODULEPOINTER;
if( p == NULL )return 0;
return 0;
besEND
/* DIM(array, elements, [base_value,] [step,] [increment,]) */
besFUNCTION(DIM)
VARIABLE Argument;
unsigned long __refcount_;
LEFTVALUE Lval;
int x, e, v, s, i, l;
besRETURNVALUE = NULL;
/* Array varable and number of elements are required */
if( besARGNR < 2 )return EX_ERROR_TOO_FEW_ARGUMENTS;
/* Number of elements */
Argument = besARGUMENT(2);
besDEREFERENCE(Argument);
e = (int)LONGVALUE(Argument);
/* Base value */
Argument = besARGUMENT(3);
besDEREFERENCE(Argument);
if( Argument ){
v = (int)LONGVALUE(Argument);
}else v = 0;
/* Step */
Argument = besARGUMENT(4);
besDEREFERENCE(Argument);
if( Argument ){
s = (int)LONGVALUE(Argument);
}else s = 1;
/* Increment */
Argument = besARGUMENT(5);
besDEREFERENCE(Argument);
if( Argument ){
i = (int)LONGVALUE(Argument);
}else i = 0;
/* Passed variable for array creation */
Argument = besARGUMENT(1);
besLEFTVALUE(Argument,Lval);
besRELEASE(*Lval);
*Lval = NULL;
*Lval = besNEWARRAY(0, e-1);
if( *Lval == NULL )return COMMAND_ERROR_MEMORY_LOW;
for( x = s - 1; ((unsigned)x) < e; x += s){
ARRAYVALUE(*Lval,x) = besNEWLONG;
LONGVALUE(ARRAYVALUE(*Lval,x)) = v;
v = v + i;
}
besEND
/* Opens a file, reads it's content and returns it into a new string variable */
besFUNCTION(file2str)
VARIABLE Argument;
char *pszFileName;
unsigned long cbString;
FILE *fp;
if( besARGNR < 1 )return COMMAND_ERROR_MANDARG;
Argument = besARGUMENT(1);
besDEREFERENCE(Argument);
Argument = besCONVERT2STRING(Argument);
besCONVERT2ZCHAR(Argument,pszFileName);
cbString = besHOOK_SIZE(pszFileName);
besRETURNVALUE = besNEWMORTALSTRING(cbString);
if( besRETURNVALUE == NULL ){
besFREE(pszFileName);
return COMMAND_ERROR_MEMORY_LOW;
}
fp = besHOOK_FOPEN(pszFileName,"rb");
if( fp == NULL ){
besFREE(pszFileName);
return COMMAND_ERROR_FILE_CANNOT_BE_OPENED;
}
besHOOK_FREAD(STRINGVALUE(besRETURNVALUE),1,cbString,fp);
besHOOK_FCLOSE(fp);
besFREE(pszFileName);
besEND
besFUNCTION(str2file)
VARIABLE Argument;
unsigned char *pszString;
char *pszFileName;
unsigned long cbString;
FILE *fp;
if( besARGNR < 2 )return COMMAND_ERROR_MANDARG;
Argument = besARGUMENT(1);
besDEREFERENCE(Argument);
Argument = besCONVERT2STRING(Argument);
besCONVERT2ZCHAR(Argument,pszFileName);
Argument = besARGUMENT(2);
besDEREFERENCE(Argument);
Argument = besCONVERT2STRING(Argument);
pszString = STRINGVALUE(Argument);
cbString = STRLEN(Argument);
fp = besHOOK_FOPEN(pszFileName,"wb");
if( fp == NULL ){
besFREE(pszFileName);
return COMMAND_ERROR_FILE_CANNOT_BE_OPENED;
}
besHOOK_FWRITE(pszString,1,cbString,fp);
besHOOK_FCLOSE(fp);
besFREE(pszFileName);
besEND
/* Returns a pointer to a ScriptBasic variable */
besFUNCTION(varptr)
VARIABLE ptr;
if(besARGNR>1) return EX_ERROR_TOO_MANY_ARGUMENTS;
if(besARGNR<1) return EX_ERROR_TOO_FEW_ARGUMENTS;
besALLOC_RETURN_LONG
ptr = besARGUMENT(1);
besDEREFERENCE(ptr);
LONGVALUE(besRETURNVALUE) = (int)ptr;
besEND
START_FUNCTION_TABLE(CBX_SLFST)
EXPORT_MODULE_FUNCTION(versmodu)
EXPORT_MODULE_FUNCTION(bootmodu)
EXPORT_MODULE_FUNCTION(finimodu)
EXPORT_MODULE_FUNCTION(DIM)
EXPORT_MODULE_FUNCTION(file2str)
EXPORT_MODULE_FUNCTION(str2file)
EXPORT_MODULE_FUNCTION(varptr)
END_FUNCTION_TABLE