CK_RV do_func(int index, Value **a)
do_func(int index, Value **a)
CK_RV do_func(int index, Value **a){    int value;    static Module module = { NULL, NULL} ;    CK_FUNCTION_LIST *func = module.functionList;    switch (commands[index].fType) {    case F_C_Initialize:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Initialize((void *)a[0]->data);    case F_C_Finalize:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Finalize((void *)a[0]->data);    case F_C_GetInfo:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetInfo((CK_INFO *)a[0]->data);    case F_C_GetFunctionList:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetFunctionList((CK_FUNCTION_LIST **)a[0]->data);    case F_C_GetSlotList:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetSlotList(*(CK_ULONG *)a[0]->data,					(CK_SLOT_ID *)a[1]->data,					(CK_LONG *)a[2]->data);    case F_C_GetSlotInfo:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetSlotInfo(*(CK_ULONG *)a[0]->data,					(CK_SLOT_INFO *)a[1]->data);    case F_C_GetTokenInfo:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetTokenInfo(*(CK_ULONG *)a[0]->data,					(CK_TOKEN_INFO *)a[1]->data);    case F_C_GetMechanismList:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	if (a[1]->data) {	    a[1]->constType = ConstMechanism;	}	return func->C_GetMechanismList(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM_TYPE*)a[1]->data,					(CK_ULONG *)a[2]->data);    case F_C_GetMechanismInfo:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetMechanismInfo(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data,					(CK_MECHANISM_INFO *)a[2]->data);    case F_C_InitToken:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_InitToken(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data);    case F_C_InitPIN:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_InitPIN(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_SetPIN:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SetPIN(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					*(CK_ULONG *)a[4]->data);    case F_C_OpenSession:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_OpenSession(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data,					(void *)NULL,					(CK_NOTIFY) NULL,					(CK_ULONG *)a[2]->data);    case F_C_CloseSession:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_CloseSession(*(CK_ULONG *)a[0]->data);    case F_C_CloseAllSessions:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_CloseAllSessions(*(CK_ULONG *)a[0]->data);    case F_C_GetSessionInfo:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetSessionInfo(*(CK_ULONG *)a[0]->data,					(CK_SESSION_INFO *)a[1]->data);    case F_C_GetOperationState:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetOperationState(*(CK_ULONG *)a[0]->data,					(CK_BYTE *)a[1]->data,					(CK_ULONG *)a[2]->data);    case F_C_SetOperationState:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SetOperationState(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					*(CK_ULONG *)a[3]->data,					*(CK_ULONG *)a[4]->data);    case F_C_Login:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Login(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data,					(CK_CHAR *)a[2]->data,					*(CK_ULONG *)a[3]->data);    case F_C_Logout:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Logout(*(CK_ULONG *)a[0]->data);    case F_C_CreateObject:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_CreateObject(*(CK_ULONG *)a[0]->data,					(CK_ATTRIBUTE *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_ULONG *)a[3]->data);    case F_C_CopyObject:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_CopyObject(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[0]->data,					(CK_ATTRIBUTE *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_ULONG *)a[3]->data);    case F_C_DestroyObject:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DestroyObject(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data);    case F_C_GetObjectSize:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetObjectSize(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data,					(CK_ULONG *)a[2]->data);    case F_C_GetAttributeValue:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetAttributeValue(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data,					(CK_ATTRIBUTE *)a[2]->data,					*(CK_ULONG *)a[3]->data);    case F_C_SetAttributeValue:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SetAttributeValue(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data,					(CK_ATTRIBUTE *)a[2]->data,					*(CK_ULONG *)a[3]->data);    case F_C_FindObjectsInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_FindObjectsInit(*(CK_ULONG *)a[0]->data,					(CK_ATTRIBUTE *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_FindObjects:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_FindObjects(*(CK_ULONG *)a[0]->data,					(CK_ULONG *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_ULONG *)a[3]->data);    case F_C_FindObjectsFinal:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_FindObjectsFinal(*(CK_ULONG *)a[0]->data);    case F_C_EncryptInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_EncryptInit(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_Encrypt:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Encrypt(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_EncryptUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_EncryptUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_EncryptFinal:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_EncryptFinal(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					(CK_ULONG *)a[2]->data);    case F_C_DecryptInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DecryptInit(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_Decrypt:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Decrypt(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_DecryptUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DecryptUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_DecryptFinal:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DecryptFinal(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					(CK_ULONG *)a[2]->data);    case F_C_DigestInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DigestInit(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data);    case F_C_Digest:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Digest(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_DigestUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DigestUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_DigestKey:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DigestKey(*(CK_ULONG *)a[0]->data,					*(CK_ULONG *)a[1]->data);    case F_C_DigestFinal:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DigestFinal(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					(CK_ULONG *)a[2]->data);    case F_C_SignInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SignInit(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_Sign:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Sign(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_SignUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SignUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_SignFinal:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SignFinal(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					(CK_ULONG *)a[2]->data);    case F_C_SignRecoverInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SignRecoverInit(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_SignRecover:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SignRecover(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_VerifyInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_VerifyInit(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_Verify:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_Verify(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					*(CK_ULONG *)a[4]->data);    case F_C_VerifyUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_VerifyUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_VerifyFinal:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_VerifyFinal(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_VerifyRecoverInit:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_VerifyRecoverInit(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_VerifyRecover:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_VerifyRecover(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_DigestEncryptUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DigestEncryptUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_DecryptDigestUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DecryptDigestUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_SignEncryptUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SignEncryptUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_DecryptVerifyUpdate:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DecryptVerifyUpdate(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_GenerateKey:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GenerateKey(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					(CK_ATTRIBUTE *)a[2]->data,					*(CK_ULONG *)a[3]->data,					(CK_ULONG *)a[4]->data);    case F_C_GenerateKeyPair:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GenerateKeyPair(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					(CK_ATTRIBUTE *)a[2]->data,					*(CK_ULONG *)a[3]->data,					(CK_ATTRIBUTE *)a[4]->data,					*(CK_ULONG *)a[5]->data,					(CK_ULONG *)a[6]->data,					(CK_ULONG *)a[7]->data);    case F_C_WrapKey:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_WrapKey(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data,					*(CK_ULONG *)a[3]->data,					(CK_CHAR *)a[5]->data,					(CK_ULONG *)a[6]->data);    case F_C_UnwrapKey:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_UnwrapKey(*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_CHAR *)a[3]->data,					*(CK_ULONG *)a[4]->data,					(CK_ATTRIBUTE *)a[5]->data,					*(CK_ULONG *)a[6]->data,					(CK_ULONG *)a[7]->data);    case F_C_DeriveKey:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_DeriveKey (*(CK_ULONG *)a[0]->data,					(CK_MECHANISM *)a[1]->data,					*(CK_ULONG *)a[2]->data,					(CK_ATTRIBUTE *)a[3]->data,					*(CK_ULONG *)a[4]->data,					(CK_ULONG *)a[5]->data);    case F_C_SeedRandom:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_SeedRandom(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_GenerateRandom:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GenerateRandom(*(CK_ULONG *)a[0]->data,					(CK_CHAR *)a[1]->data,					*(CK_ULONG *)a[2]->data);    case F_C_GetFunctionStatus:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_GetFunctionStatus(*(CK_ULONG *)a[0]->data);    case F_C_CancelFunction:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_CancelFunction(*(CK_ULONG *)a[0]->data);    case F_C_WaitForSlotEvent:	if (!func) return CKR_CRYPTOKI_NOT_INITIALIZED;	return func->C_WaitForSlotEvent(*(CK_ULONG *)a[0]->data,					(CK_ULONG *)a[1]->data,					(void *)a[2]->data);    /* set a variable */    case F_SetVar:		(void) DeleteVariable(a[0]->data);	(void) AddVariable(a[0]->data,&a[1]);	return CKR_OK;    /* print a value */    case F_Print:	return printArg(a[0],0);    case F_SaveVar:	return save(a[0]->data,a[1]);    case F_RestoreVar:	return restore(a[0]->data,a[1]);    case F_Delete:	return DeleteVariable(a[0]->data);    case F_List:	return list();    case F_Run:	return run(a[0]->data);    case F_Load:	return loadModule(&module,a[0]->data);    case F_Unload:	return unloadModule(&module);    case F_NewArray:	(void) DeleteVariable(a[0]->data);	return ArrayVariable(a[0]->data,a[1]->data,*(CK_ULONG *)a[2]->data);    case F_NewTemplate:	(void) DeleteVariable(a[0]->data);	return ArrayTemplate(a[0]->data,a[1]->data);    case F_BuildTemplate:	return BuildTemplate(a[0]);    case F_SetTemplate:	return SetTemplate(a[0],		*(CK_ULONG *)a[1]->data,		*(CK_ULONG *)a[2]->data);    case F_NewMechanism:	(void) DeleteVariable(a[0]->data);	return NewMechanism(a[0]->data,*(CK_ULONG *)a[1]->data);    case F_System:        value = *(int *)a[0]->data;	if (value & 0x80000000) {	    systemFlags &= ~value;	} else {	    systemFlags |= value;	}	return CKR_OK;    case F_Quit:	return 0x80000000;    default:	fprintf(stderr,		"Function %s not yet supported\n",commands[index].fname );	return CKR_OK;    }    /* Not Reached */    return CKR_OK;}