Beispiel #1
0
LPCSTR FTP::InsertCurrentToQueue(void)
{
	PanelInfo   pi, api;
	FP_SizeItemList backup,il;
	FTPCopyInfo ci;

	if(!FP_Info->Control(this, FCTL_GETPANELINFO, &pi) ||
	        !FP_Info->Control(INVALID_HANDLE_VALUE, FCTL_GETANOTHERPANELSHORTINFO, &api))
		return FMSG(MErrGetPanelInfo);

	if(pi.SelectedItemsNumber <= 0 ||
	        pi.SelectedItemsNumber == 1 && !IS_FLAG(pi.SelectedItems[0].Flags,PPIF_SELECTED))
		return FMSG(MErrNoSelection);

	backup.Add(pi.SelectedItems, pi.SelectedItemsNumber);
	BOOL rc = ExpandList(backup.Items(), backup.Count(), &il, TRUE);
	FP_Screen::FullRestore();

	if(!rc)
		return GetLastError() == ERROR_CANCELLED ? NULL : FMSG(MErrExpandList);

	ci.Download = TRUE;

	if(api.PanelType != PTYPE_FILEPANEL || api.Plugin)
		ci.DestPath = "";
	else
		ci.DestPath = api.CurDir;

	ListToQueque(&il, &ci);
	return NULL;
}
Beispiel #2
0
LPCSTR FTP::InsertAnotherToQueue(void)
{
	FP_SizeItemList backup,il;
	PanelInfo       pi;
	FTPCopyInfo     ci;

	if(!hConnect || ShowHosts)
		return FMSG(MQErrUploadHosts);

	if(!FP_Info->Control(INVALID_HANDLE_VALUE, FCTL_GETANOTHERPANELINFO, &pi))
		return FMSG(MErrGetPanelInfo);

	if(pi.SelectedItemsNumber <= 0 ||
	        pi.SelectedItemsNumber == 1 && !IS_FLAG(pi.SelectedItems[0].Flags,PPIF_SELECTED))
		return FMSG(MErrNoSelection);

	if(pi.PanelType != PTYPE_FILEPANEL || pi.Plugin)
		return FMSG(MErrNotFiles);

	backup.Add(pi.SelectedItems, pi.SelectedItemsNumber);
	BOOL rc = ExpandList(backup.Items(), backup.Count(), &il, FALSE);
	FP_Screen::FullRestore();

	if(!rc)
		return GetLastError() == ERROR_CANCELLED ? NULL : FMSG(MErrExpandList);

	ci.Download = FALSE;
	GetCurPath(ci.DestPath);
	ListToQueque(&il, &ci);
	return NULL;
}
Beispiel #3
0
int AskDeleteQueue(void)
{
	LPCSTR MsgItems[] =
	{
		FMSG(MAttention),
		FMSG(MQDeleteItem),
		FMSG(MQSingleItem), FMSG(MQEntireList), FMSG(MCancel)
	};
	return FMessage(FMSG_WARNING, NULL, MsgItems, ARRAYSIZE(MsgItems),3);
}
void
mas_atexit( void )
{
#ifdef MAS_TRACEMEM
  extern unsigned long memory_balance;

  FMSG( "AT EXIT, memory_balance:%ld", memory_balance );
#else
  FMSG( "AT EXIT" );
#endif
  FMSG( "======================================================================" );
}
Beispiel #5
0
TEE_Result crypto_acipher_gen_ecc_key(struct ecc_keypair *key)
{
	TEE_Result res = TEE_SUCCESS;
	int lmd_res = 0;
	mbedtls_ecdsa_context ecdsa;
	size_t key_size_bytes = 0;
	size_t key_size_bits = 0;

	memset(&ecdsa, 0, sizeof(ecdsa));

	res = ecc_get_keysize(key->curve, 0, &key_size_bytes, &key_size_bits);
	if (res != TEE_SUCCESS)
		return res;

	mbedtls_ecdsa_init(&ecdsa);

	/* Generate the ECC key */
	lmd_res = mbedtls_ecdsa_genkey(&ecdsa, key->curve, mbd_rand, NULL);
	if (lmd_res != 0) {
		res = TEE_ERROR_BAD_PARAMETERS;
		FMSG("mbedtls_ecdsa_genkey failed.");
		goto exit;
	}
	ecc_clear_precomputed(&ecdsa.grp);

	/* check the size of the keys */
	if ((mbedtls_mpi_bitlen(&ecdsa.Q.X) > key_size_bits) ||
	    (mbedtls_mpi_bitlen(&ecdsa.Q.Y) > key_size_bits) ||
	    (mbedtls_mpi_bitlen(&ecdsa.d) > key_size_bits)) {
		res = TEE_ERROR_BAD_PARAMETERS;
		FMSG("Check the size of the keys failed.");
		goto exit;
	}

	/* check LMD is returning z==1 */
	if (mbedtls_mpi_bitlen(&ecdsa.Q.Z) != 1) {
		res = TEE_ERROR_BAD_PARAMETERS;
		FMSG("Check LMD failed.");
		goto exit;
	}

	/* Copy the key */
	crypto_bignum_copy(key->d, (void *)&ecdsa.d);
	crypto_bignum_copy(key->x, (void *)&ecdsa.Q.X);
	crypto_bignum_copy(key->y, (void *)&ecdsa.Q.Y);

	res = TEE_SUCCESS;
exit:
	mbedtls_ecdsa_free(&ecdsa);		/* Free the temporary key */
	return res;
}
Beispiel #6
0
void tee_svc_trace_syscall(int num)
{
	/* #0 is syscall return, not really interesting */
	if (num == 0)
		return;
	FMSG("syscall #%d", num);
}
Beispiel #7
0
LPCSTR FTP::CloseQuery(void)
{
	if(UrlsList != NULL)
		return FMSG("Process queque is not empty");

	return NULL;
}
Beispiel #8
0
BOOL FtpGetFile(Connection *Connect,LPCSTR lpszRemoteFile,LPCSTR lpszNewFile,BOOL Reget,int AsciiMode)
{
	PROC(("FtpGetFile","[%s]->[%s] %s %s",lpszRemoteFile,lpszNewFile,Reget?"REGET":"NEW",AsciiMode?"ASCII":"BIN"));
	String Command,
	       full_name;
	int  ExitCode;
	Assert(Connect && "FtpGetFile");

//mode
	if(AsciiMode && !Connect->ProcessCommand("ascii"))
	{
		Log(("!ascii ascii:%d",AsciiMode));
		return FALSE;
	}
	else if(!AsciiMode && !Connect->ProcessCommand("bin"))
	{
		Log(("!bin ascii:%d",AsciiMode));
		return FALSE;
	}

//Create directory
	Command = lpszNewFile;
	int m = Command.RChr('/');

	if(m != -1)
	{
		Command.SetLength(m);

		if(!DoCreateDirectory(Command.c_str()))
		{
			Log(("!CreateDirectory [%s]",Command.c_str()));
			return FALSE;
		}
	}

//Remote file
	if(Connect->Host.ServerType!=FTP_TYPE_MVS && *lpszRemoteFile != '/')
	{
		full_name = Connect->CurDir; //Connect->ToOEMDup(Connect->CurDir.c_str());
		AddEndSlash(full_name, '/');
		full_name.Add(lpszRemoteFile);
		lpszRemoteFile = full_name.c_str();
	}

//Get file
	Connect->IOCallback = TRUE;

	if(Reget && !Connect->ResumeSupport)
	{
		Connect->AddCmdLine(FMSG(MResumeRestart));
		Reget = FALSE;
	}

	Command.printf("%s \x1%s\x1 \x1%s\x1",
	               Reget ? "reget":"get",
	               lpszRemoteFile, lpszNewFile);
	ExitCode = Connect->ProcessCommand(Command);
	Connect->IOCallback = FALSE;
	return ExitCode;
}
Beispiel #9
0
/**
 * Returns the neutral element of the multiplication operation of the weight
 * semiring.
 *
 * @param nSrType Semiring type (<code>FST_WSR_PROB</code>,
 *                <code>FST_WSR_LOG</code> or <code>FST_WSR_TROP</code>)
 * @return The neutral element
 */
FST_WTYPE CGEN_SPROTECTED CFst_Wsr_NeMult(INT16 nSrType)
{
  switch (nSrType)
  {
    case FST_WSR_PROB: return 1.;
    case FST_WSR_LOG : return 0.;
    case FST_WSR_TROP: return 0.;
    case 0           : return 0.;                                              /* Not weighted; just do nothing */
    default          : DLPASSERT(FMSG("Invalid weight semiring type"));
  }
  return 0.;
}
Beispiel #10
0
/**
 * Prints the instance in text mode (exactly one component of type 1).
 */
INT16 CGEN_PRIVATE CData_PrintText(CData* _this)
{
  INT32  nR   = 0;                                                               /* Current record                    */
  INT32  nXR  = 0;                                                               /* Number of records                 */
  char* tx   = NULL;                                                            /* Auxilary char pointer #1          */
  char* tx0  = NULL;                                                            /* Pointer to string                 */
  char* ty   = NULL;                                                            /* Auxilary char pointer #2          */
  char* ty0  = NULL;                                                            /* Pointer to last white space       */
  INT32  nCtr = 0;                                                               /* Line counter                      */
  char  sBuf[255];                                                              /* Printing buffer                   */

  /* Initialize */                                                              /* --------------------------------- */
  nXR = CData_GetNRecs(_this);                                                  /* Get number of records             */

  /* Print data contents as text */                                             /* --------------------------------- */
  DLPASSERT(FMSG("ALPHA: String mode not tested yet"));                         /* TODO: Remove after debugging      */
  printf("\n  String Mode"); dlp_inc_printlines(1);                             /* Protocol                          */
  tx0=tx=(char*)CData_XAddr(_this,0,0);                                         /* Initialize char pointers          */
  if (!*tx)                                                                     /* Empty string                      */
  {                                                                             /* >>                                */
    printf("\n  [empty]");                                                      /*   Protocol                        */
    dlp_inc_printlines(1);                                                      /*   Adjust no. of printed lines     */
  }                                                                             /* <<                                */
  else while (*tx)                                                              /* Loop over characters              */
  {                                                                             /* >>                                */
    /* Make line breaks */                                                      /*   - - - - - - - - - - - - - - - - */
    for (ty=tx,ty0=NULL; *ty && ty<tx0+nXR; )                                   /*   Do until end of string          */
    {                                                                           /*   >>                              */
      while (*ty && ty<tx0+nXR && !iswspace(*ty)) ty++;                         /*     Seek next white space         */
      while (*ty && ty<tx0+nXR &&  iswspace(*ty)) ty++;                         /*     Skip following white spaces   */
      ty0=ty;                                                                   /*     Remember previous white spc.  */
      if (ty>tx+dlp_maxprintcols()-16) break;                                   /*     Line full                     */
    }                                                                           /*   <<                              */
    if (ty0) ty=ty0;                                                            /*   Go back to last white space     */

    /* Print one line */                                                        /*   - - - - - - - - - - - - - - - - */
    dlp_memset(sBuf,0,255);                                                     /*   Clear printing buffer           */
    dlp_memmove(sBuf,tx,ty-tx);                                                 /*   Copy characters in              */
    printf("\n  %4d(%06d): %s",(int)nCtr,(int)(tx-tx0),sBuf);                   /*   Print 'em                       */
    dlp_inc_printlines(1);                                                      /*   Adjust no. of printed lines     */
    if (dlp_if_printstop()) break;                                              /*   Break listing                   */

    /* End-of-line actions */                                                   /*   - - - - - - - - - - - - - - - - */
    DLPASSERT(ty>tx);                                                           /*   Should have made some progress  */
    tx=ty;                                                                      /*   Move to end of printed line     */
    nCtr++;                                                                     /*   Increment line counter          */
  }                                                                             /* <<                                */
  if (nR>=nXR) printf("\n  No more data - Stop.");                              /* Protocol                          */
  else         printf("\n  Cancelled - Stop.");                                 /* Protocol                          */
  return O_K;                                                                   /* Ok                                */
}
Beispiel #11
0
void FTP::InsertToQueue(void)
{
	static LPCSTR strings[] =
	{
		FMSG(MQISingle),
		FMSG(MQIFTP),
		FMSG(MQIAnother),
		NULL
	};
	FP_Menu  mnu(strings);
	int      sel;
	LPCSTR err;
	FTPUrl   tmp;

	do
	{
		sel = mnu.Execute(FMSG(MQAddTitle),FMENU_WRAPMODE,NULL,"FTPQueueAddItem");

		if(sel == -1)
			return;

		err = NULL;

		switch(sel)
		{
			case 0:
				UrlInit(&tmp);

				if(EditUrlItem(&tmp))
				{
					AddToQueque(&tmp);
					return;
				}

				break;
			case 1:
				err = InsertCurrentToQueue();

				if(!err && GetLastError() != ERROR_CANCELLED) return;

				break;
			case 2:
				err = InsertAnotherToQueue();

				if(!err && GetLastError() != ERROR_CANCELLED) return;

				break;
		}

		if(err)
		{
			static LPCSTR itms[] = { FMSG(MQErrAdding), NULL, FMSG(MOk) };
			itms[1] = err;
			FMessage(FMSG_WARNING,NULL,itms,3,1);
		}
	}
	while(true);
}
Beispiel #12
0
//---------------------------------------------------------------------------------
BOOL WarnOldFormat(FTPHost* h)
{
	static LPCSTR items[] =
	{
		FMSG(MOldHostFormatTitle),
		FMSG(MOldHostFormat1),
		NULL,
		FMSG("\x1"),
		FMSG(MOldHostFormat2),
		FMSG(MOldHostFormat3),
		FMSG("\x1"),
		FMSG(MOldHostConvert), FMSG(MCancel)
	};
	items[2] = h->HostName;
	return FMessage(FMSG_WARNING | FMSG_LEFTALIGN, "WarnOldFmt", items, ARRAYSIZE(items), 2) == 0;
}
Beispiel #13
0
/*
 * Manual page at function.def
 */
INT16 CGEN_PUBLIC CFunction::OnGet()
{
  // Delegate to running function                                               // ------------------------------------
  FNC_DELEGATE OnGet();                                                         // Use a weird macro (see function.def)

  // Initialize                                                                 // ------------------------------------
  CDlpObject* iCont = GetActiveInstance();                                      // Determine field container
  const char* lpsId = GetNextToken(TRUE);                                       // Determine field name

  // Validate                                                                   // ------------------------------------
  DLPASSERT(iCont);                                                             // Check set target
  if (!dlp_strlen(lpsId))                                                       // If no field name committed
    return IERROR(this,FNC_EXPECT,"field identifier after -get",0,0);           //   Error
  SWord* lpWrd = iCont->FindWord(lpsId,WL_TYPE_FIELD);                          // Find field in container
  if (!lpWrd)                                                                   // If not found
  {                                                                             // >>
    iCont = this;                                                               //   Use this instance as container
    lpWrd = FindWord(lpsId,WL_TYPE_FIELD);                                      //   And seek again
  }                                                                             // <<
  if (!lpWrd) return IERROR(this,ERR_NOTFIELD,lpsId,0,0);                       // If still not found --> Error

  // Push field value                                                           // ------------------------------------
  switch (lpWrd->ex.fld.nType)                                                  // Branch for field variable type
  {                                                                             // >>
    case T_BOOL    : { PushLogic   (      *(     BOOL*)lpWrd->lpData);  break; }// - Boolean
    case T_UCHAR   : { PushNumber  (CMPLX(*(    UINT8*)lpWrd->lpData)); break; }// - Unsigned character
    case T_CHAR    : { PushNumber  (CMPLX(*(     INT8*)lpWrd->lpData)); break; }// - Signed character
    case T_USHORT  : { PushNumber  (CMPLX(*(   UINT16*)lpWrd->lpData)); break; }// - Unsigned short integer
    case T_SHORT   : { PushNumber  (CMPLX(*(    INT16*)lpWrd->lpData)); break; }// - Signed short integer
    case T_UINT    : { PushNumber  (CMPLX(*(   UINT32*)lpWrd->lpData)); break; }// - Unsigned integer
    case T_INT     : { PushNumber  (CMPLX(*(    INT32*)lpWrd->lpData)); break; }// - Signed integer
    case T_ULONG   : { PushNumber  (CMPLX(*(   UINT64*)lpWrd->lpData)); break; }// - Unsigned long integer
    case T_LONG    : { PushNumber  (CMPLX(*(    INT64*)lpWrd->lpData)); break; }// - Signed long integer
    case T_FLOAT   : { PushNumber  (CMPLX(*(  FLOAT32*)lpWrd->lpData)); break; }// - Single precision floating point
    case T_DOUBLE  : { PushNumber  (CMPLX(*(  FLOAT64*)lpWrd->lpData)); break; }// - Double precision floating point
    case T_COMPLEX : { PushNumber  (      *(COMPLEX64*)lpWrd->lpData);  break; }// - Double precision complex floating point
    case T_INSTANCE: { PushInstance(*(CDlpObject**) lpWrd->lpData);     break; }// - Instance
    case T_TEXT    : /* Fall through */                                         // - Text (deprecated type!)
    case T_CSTRING : /* Fall through */                                         // - Constant string
    case T_STRING  : { PushString(*(char**)         lpWrd->lpData); break;     }// - String
    default        : {                                                          // - Other types
      if (lpWrd->ex.fld.nType > 0 && lpWrd->ex.fld.nType <= 256)                //     Character array?
        PushString((char*)lpWrd->lpData);                                       //       Push value
      else                                                                      //     Type unknown!
        DLPASSERT(FMSG("Unknown field type"));                                  //       Error
    }                                                                           //   <<
  }                                                                             // <<

  return O_K;                                                                   // Done.
}
Beispiel #14
0
void core_trace_test(void)
{
	INMSG("level: [%d]", _trace_level);
	IMSG("current trace level = %d", _trace_level);
	IMSG("Without args");
	AMSG("[%d] and [%s]", TRACE_ALWAYS, "TRACE_ALWAYS");
	EMSG("[%d] and [%s]", TRACE_ERROR, "TRACE_ERROR");
	IMSG("[%d] and [%s]", TRACE_INFO, "TRACE_INFO");
	DMSG("[%d] and [%s]", TRACE_DEBUG, "TRACE_DEBUG");
	FMSG("[%d] and [%s]", TRACE_FLOW, "TRACE_FLOW");
	AMSG_RAW("Raw trace in TEE CORE with level [%s]", "TRACE_ALWAYS");
	AMSG_RAW(" __ end of raw trace\n");
	DMSG_RAW("Raw trace in TEE CORE with level [%s]", "TRACE_DEBUG");
	DMSG_RAW(" __ end of raw trace\n");
	OUTMSG("");
}
Beispiel #15
0
/**
 * Removes the variable's value from the stack. This method <em>must</em> be
 * called from all interactive methods.
 * 
 * @see Exec
 */
void CGEN_PROTECTED CVar_PopOwnValue(CVar *_this)
{
  switch (_this->m_nType)
  {
    case T_BOOL:
      CDlpObject_MicGetB(BASEINST(_this),-1,0);
      break;
    case T_COMPLEX:
    case T_RDOUBLE:
    case T_RDDATA:
      CDlpObject_MicGetN(BASEINST(_this),-1,0);
      break;
    case T_STRING:
    case T_RSDATA:
      CDlpObject_MicGetS(BASEINST(_this),-1,0);
      break;
    case T_INSTANCE:
      CDlpObject_MicGetI(BASEINST(_this),-1,0);
      break;
    default: DLPASSERT(FMSG("Unknown variable type"));
  }
}
Beispiel #16
0
/**
 * <p>INTERNAL USE ONLY. This method is called by {@link -pool} to pool the
 * statistics blocks contained in <code>idSrc</code> and store the result in
 * <code>idPool</code>. The operation is controlled through the pooling mode
 * flag <code>nMode</code> as follows:</p>
 *
 * <ul>
 *   <li>nMode=0: Pool sum data, <code>idPool</code> will be overwritten</li>
 *   <li>nMode=1: Pool min data</li>
 *   <li>nMode=2: Pool max data</li>
 * </ul>
 *
 * <h3>Remarks</h3>
 * <ul>
 *   <li>In order to pool raw statistics data, there are three calls
 *     (<code>nMode</code>=0,1 and 2) necessary. The first call of these
 *     <em>must</em> be the one with <code>nMode</code>=0!</li>
 *   <li>There are NO checks performed</li>
 * </ul>
 *
 * @param idPool
 *          Pooled raw statistics data block
 * @param idSrc
 *          Raw statistics data blocks to be pooled
 * @param nMode
 *          Pooling mode, see above
 */
void CGEN_SPRIVATE CStatistics_PoolInt(CData* idPool, CData* idSrc, INT32 nMode)
{
  CData* idAux      = NULL;                                                     /* Auxilary data instance #1         */

  if (nMode==0)                                                                 /* Sum aggregation mode              */
  {                                                                             /* >>                                */
    ISETOPTION(idPool,"/block");                                                /*   Switch target to block mode     */
    CData_Aggregate(idPool,idSrc,NULL,CMPLX(0),"sum");                          /*   Aggregate (sum up)              */
    IRESETOPTIONS(idPool);                                                      /*   Switch target to normal mode    */
  }                                                                             /* <<                                */
  else if (nMode==1 || nMode==2)                                                /* Extrama aggregation modes         */
  {                                                                             /* >>                                */
    ICREATEEX(CData,idAux,"CStatistics_Pool_int.~idAux",NULL);                  /*   Create auxilary data instance #1*/
    ISETOPTION(idAux,"/block");                                                 /*   Switch target to block mode     */
    CData_Aggregate(idAux,idSrc,NULL,CMPLX(0),nMode==1?"min":"max");            /*   Aggregate (minimum or maximum)  */
    dlp_memmove(CData_XAddr(idPool,nMode,0),CData_XAddr(idAux,nMode,0),         /*   Copy aggregated min. or max. ...*/
      CData_GetRecLen(idAux));                                                  /*   | ... to target                 */
    IRESETOPTIONS(idAux);                                                       /*   Switch target to normal mode    */
    IDESTROY(idAux);                                                            /*   Destroy auxilary data inst. #1  */
  }                                                                             /* <<                                */
  else                                                                          /* Unknown mode                      */
    DLPASSERT(FMSG("Invalid internal pooling mode"));                           /*   Not so good ...                 */
}
Beispiel #17
0
/**
 * Implementation of the class function. Leaves the value of the variable on
 * the stack.
 */
void CGEN_PROTECTED CVar_Exec(CVar *_this)
{
  switch (_this->m_nType)
  {
    case T_BOOL:
      CDlpObject_MicPutB(BASEINST(_this),_this->m_bBVal);
      break;
    case T_DOUBLE:
    case T_COMPLEX:
      CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal);
      break;
    case T_STRING:
      CDlpObject_MicPutS(BASEINST(_this),_this->m_lpsSVal);
      break;
    case T_INSTANCE:
      CDlpObject_MicPutI(BASEINST(_this),BASEINST(_this)->m_iAliasInst);
      break;
    case T_RDOUBLE: {
      _this->m_nInd  = (INT32)(rand()/_this->m_nNorm);
      _this->m_nNVal = CMPLX(_this->m_nLow+_this->m_nInd*_this->m_nDelta);
      CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal);
      break; }
    case T_RDDATA:
      _this->m_nInd  = (INT32)(rand()/_this->m_nNorm);
      _this->m_nNVal = CData_Cfetch(AS(CData,_this->m_idRndSet),_this->m_nInd, _this->m_nIcomp);
      CDlpObject_MicPutN(BASEINST(_this),_this->m_nNVal);
      break;
    case T_RSDATA:
      _this->m_nInd = (INT32)(rand()/_this->m_nNorm);
      CVar_Sset(_this,(char*)CData_XAddr(AS(CData,_this->m_idRndSet),_this->m_nInd,_this->m_nIcomp));
      _this->m_nType = T_RSDATA;
      CDlpObject_MicPutS(BASEINST(_this),_this->m_lpsSVal);
      break;
    default: DLPASSERT(FMSG("Unknown variable type"));
  }
}
Beispiel #18
0
//------------------------------------------------------------------------
LPCSTR GetOtherPath(char *path)
{
	PanelInfo pi;

	do
	{
		if(FP_Info->Control(INVALID_HANDLE_VALUE, FCTL_GETANOTHERPANELSHORTINFO, &pi) &&
		        pi.PanelType == PTYPE_FILEPANEL &&
		        !pi.Plugin)
			break;

		if(FP_Info->Control(INVALID_HANDLE_VALUE, FCTL_GETPANELSHORTINFO, &pi) &&
		        pi.PanelType == PTYPE_FILEPANEL &&
		        !pi.Plugin)
			break;

		return FMSG(MFLErrGetInfo);
	}
	while(0);

	StrCpy(path, pi.CurDir, MAX_PATH);
	AddEndSlash(path,'\\',MAX_PATH);
	return NULL;
}
Beispiel #19
0
BOOL FTP::WarnExecuteQueue(QueueExecOptions* op)
{
	InitDialogItem InitItems[]=
	{
		{DI_DOUBLEBOX, 3, 1,72, 9, 0, 0,0,0,FMSG(MQueueParam)},

		{DI_CHECKBOX,5, 3,0,0,0,    0,0,0,FMSG(MQRestore)},
		{DI_CHECKBOX,5, 4,0,0,0,    0,0,0,FMSG(MQRemove)},

		{DI_CHECKBOX,5, 6,0,0,0,    0,0,0,FMSG(MQSave)},

		{DI_TEXT,3, 7,3, 7,DIF_BOXCOLOR|DIF_SEPARATOR,0,0,0,NULL },
		{DI_BUTTON,0, 8,0,0,DIF_CENTERGROUP, 0,0,1,   FMSG(MOk)},
		{DI_BUTTON,0, 8,0,0,DIF_CENTERGROUP, 0,0,0,   FMSG(MCancel)},
	};
	FarDialogItem  DialogItems[ARRAYSIZE(InitItems)];
//Create items
	InitDialogItems(InitItems,DialogItems,ARRAYSIZE(DialogItems));
//Set flags
	//Flags
	DialogItems[ 1].Selected = op->RestoreState;
	DialogItems[ 2].Selected = op->RemoveCompleted;

//Dialog
	if(FDialog(76,11,"FTPProcessQueue",DialogItems,ARRAYSIZE(DialogItems)) != 5)
		return FALSE;

//Get paras
	//Flags
	op->RestoreState     = DialogItems[ 1].Selected;
	op->RemoveCompleted  = DialogItems[ 2].Selected;

	//Save to default
	if(DialogItems[ 3].Selected)
	{
		Opt.RestoreState    = op->RestoreState;
		Opt.RemoveCompleted = op->RemoveCompleted;
		FP_SetRegKey("QueueRestoreState",    Opt.RestoreState);
		FP_SetRegKey("QueueRemoveCompleted", Opt.RemoveCompleted);
	}

	return TRUE;
}
Beispiel #20
0
TEE_Result crypto_acipher_ecc_verify(uint32_t algo, struct ecc_public_key *key,
				     const uint8_t *msg, size_t msg_len,
				     const uint8_t *sig, size_t sig_len)
{
	TEE_Result res = TEE_SUCCESS;
	int lmd_res = 0;
	mbedtls_ecdsa_context ecdsa;
	size_t key_size_bytes, key_size_bits = 0;
	uint8_t one[1] = { 1 };
	mbedtls_mpi r;
	mbedtls_mpi s;

	memset(&ecdsa, 0, sizeof(ecdsa));
	memset(&r, 0, sizeof(r));
	memset(&s, 0, sizeof(s));

	if (algo == 0)
		return TEE_ERROR_BAD_PARAMETERS;

	mbedtls_mpi_init(&r);
	mbedtls_mpi_init(&s);

	mbedtls_ecdsa_init(&ecdsa);

	lmd_res = mbedtls_ecp_group_load(&ecdsa.grp, key->curve);
	if (lmd_res != 0) {
		res = TEE_ERROR_NOT_SUPPORTED;
		goto out;
	}

	ecdsa.Q.X = *(mbedtls_mpi *)key->x;
	ecdsa.Q.Y = *(mbedtls_mpi *)key->y;
	mbedtls_mpi_read_binary(&ecdsa.Q.Z, one, sizeof(one));

	res = ecc_get_keysize(key->curve, algo,
			      &key_size_bytes, &key_size_bits);
	if (res != TEE_SUCCESS) {
		res = TEE_ERROR_BAD_PARAMETERS;
		goto out;
	}

	/* check keysize vs sig_len */
	if ((key_size_bytes * 2) != sig_len) {
		res = TEE_ERROR_BAD_PARAMETERS;
		goto out;
	}

	mbedtls_mpi_read_binary(&r, sig, sig_len / 2);
	mbedtls_mpi_read_binary(&s, sig + sig_len / 2, sig_len / 2);

	lmd_res = mbedtls_ecdsa_verify(&ecdsa.grp, msg, msg_len, &ecdsa.Q,
				       &r, &s);
	if (lmd_res != 0) {
		FMSG("mbedtls_ecdsa_verify failed, returned 0x%x", -lmd_res);
		res = get_tee_result(lmd_res);
	}
out:
	mbedtls_mpi_free(&r);
	mbedtls_mpi_free(&s);
	/* Reset mpi to skip freeing here, those mpis will be freed with key */
	mbedtls_mpi_init(&ecdsa.Q.X);
	mbedtls_mpi_init(&ecdsa.Q.Y);
	mbedtls_ecdsa_free(&ecdsa);
	return res;
}
Beispiel #21
0
TEE_Result crypto_acipher_ecc_sign(uint32_t algo, struct ecc_keypair *key,
				   const uint8_t *msg, size_t msg_len,
				   uint8_t *sig, size_t *sig_len)
{
	TEE_Result res = TEE_SUCCESS;
	int lmd_res = 0;
	const mbedtls_pk_info_t *pk_info = NULL;
	mbedtls_ecdsa_context ecdsa;
	size_t key_size_bytes = 0;
	size_t key_size_bits = 0;
	mbedtls_mpi r;
	mbedtls_mpi s;

	memset(&ecdsa, 0, sizeof(ecdsa));
	memset(&r, 0, sizeof(r));
	memset(&s, 0, sizeof(s));

	if (algo == 0)
		return TEE_ERROR_BAD_PARAMETERS;

	mbedtls_mpi_init(&r);
	mbedtls_mpi_init(&s);

	mbedtls_ecdsa_init(&ecdsa);
	lmd_res = mbedtls_ecp_group_load(&ecdsa.grp, key->curve);
	if (lmd_res != 0) {
		res = TEE_ERROR_NOT_SUPPORTED;
		goto out;
	}

	ecdsa.d = *(mbedtls_mpi *)key->d;

	res = ecc_get_keysize(key->curve, algo, &key_size_bytes,
			      &key_size_bits);
	if (res != TEE_SUCCESS)
		goto out;

	pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECDSA);
	if (pk_info == NULL) {
		res = TEE_ERROR_NOT_SUPPORTED;
		goto out;
	}

	lmd_res = mbedtls_ecdsa_sign(&ecdsa.grp, &r, &s, &ecdsa.d, msg,
				     msg_len, mbd_rand, NULL);
	if (lmd_res == 0) {
		*sig_len = 2 * key_size_bytes;
		memset(sig, 0, *sig_len);
		mbedtls_mpi_write_binary(&r, sig + *sig_len / 2 -
					 mbedtls_mpi_size(&r),
					 mbedtls_mpi_size(&r));

		mbedtls_mpi_write_binary(&s, sig + *sig_len -
					 mbedtls_mpi_size(&s),
					 mbedtls_mpi_size(&s));
		res = TEE_SUCCESS;
	} else {
		FMSG("mbedtls_ecdsa_sign failed, returned 0x%x\n", -lmd_res);
		res = TEE_ERROR_GENERIC;
	}
out:
	mbedtls_mpi_free(&r);
	mbedtls_mpi_free(&s);
	/* Reset mpi to skip freeing here, those mpis will be freed with key */
	mbedtls_mpi_init(&ecdsa.d);
	mbedtls_ecdsa_free(&ecdsa);
	return res;
}
Beispiel #22
0
/* NO JAVADOC
 * Calculates the Mahalanobis distance or the (logarithmic) probability density
 * of a feature vector given a single Gaussian distribution. There are NO CHECKS
 * performed.
 * 
 * Complexity: 2N + N*N where N=m_nDim
 * 
 * @author Rainer Schaffer
 * @param _this
 *          Pointer to GMM instance
 * @param x
 *          Feature vector (expected to have N=m_nDim values
 * @param k
 *          Index of single Gaussian
 * @param nMode
 *          Operation mode, one of the GMMG_XXX constants
 * @return  The (logarithmic) probability density or Mahalanobis distance of x
 *          in single Gaussian k.
 */
double CGmm_GaussD_SSE2(CGmm* _this, double* x, INT32 k, INT16 nMode)
{
  INT32            dim;                                                          /* Feature space dimensionality      */
  double*         icov;                                                         /* Ptr. to inverse covariance matrix */
  double*         h;                                                            /* Ptr. to aux.buffer (2*dim doubles)*/
  double*         m;                                                            /* Ptr. to mean vector               */
  short            i = 0, j = 0;                                                 /* (Rainer's variables)              */
  volatile double tsum[2];                                                      /* (Rainer's variables)              */
  register double *covd, *covd2;                                                /* (Rainer's variables)              */

  dim  = _this->m_nN;                                                           /* Initialize Rainer's varibles      */
  m    = &((double*)CData_XAddr(_this->m_idMean,0,0))[k*dim];                   /* Initialize Rainer's varibles      */
  icov = &((double*)CData_XAddr(_this->m_idSse2Icov,0,0))[k*dim*dim];           /* Initialize Rainer's varibles      */
  h    = (double*)_this->m_lpSse2Buf;                                           /* Initialize Rainer's varibles      */
  if (*(double*)CData_XAddr(_this->m_idCdet,k,0)==0.)                           /* Covariance matrix invalid         */
    return CGmm_GetLimit(_this,nMode);                                          /*   Return limit                    */

  /* ---- Rainer's code ----> */
  if( m == NULL ) 
    return(.0);

  /* Bestimmung der ersten Werte der Matrix-Vektor-Multiplikation (i = 0) */
  covd = &icov[0];
  covd2 = &icov[dim];
  xorpd_r2r( xmm3, xmm3 );  /* Ergebnisvektor xmm3 (Vekt-Vekt-Mult) l�schen */
  movapd_r2r( xmm3, xmm6 ); /* Ergebnisvektor xmm6 (Matr-Vekt-Mult) l�schen */
  movapd_r2r( xmm3, xmm7 ); /* Ergebnisvektor xmm7 (Matr-Vekt-Mult) l�schen */
  for( j = 0; j < dim-1; j += 2 ){ 
    /* Differenz zweier Vektoren (m-x) */
    movupd_m2r( *(m+j), xmm0 );
    movupd_m2r( *(x+j), xmm1 );
    subpd_r2r( xmm1, xmm0 );
    movupd_r2m( xmm0, *(h+j) );
    /* Bestimmung der Elemente */
    movupd_m2r( *(covd+j), xmm1 );
    movupd_m2r( *(covd2+j), xmm2 );
    mulpd_r2r( xmm0, xmm1 );
    mulpd_r2r( xmm0, xmm2 );
    addpd_r2r( xmm1, xmm6 );
    addpd_r2r( xmm2, xmm7 );
  }
  movapd_r2r( xmm6, xmm0 );
  movlhps_r2r( xmm7, xmm6 );
  movhlps_r2r( xmm0, xmm7 );
  addpd_r2r( xmm6, xmm7 );
  for( ; j < dim; ++j ){ /* Durchf�hrung nichtparalleler Befehle */
    h[j] = m[j] - x[j]; 
    tsum[0] = covd[j]*h[j];
    tsum[1] = covd2[j]*h[j];
    movupd_m2r( *tsum, xmm0 );
    addpd_r2r( xmm0, xmm7 );
  } 
  /* Vektor-Vektor-Multiplikation (1. Teil) */
  movupd_m2r( *(h), xmm0 );
  mulpd_r2r( xmm7, xmm0 );
  addpd_r2r( xmm0, xmm3 );
  

  /* Bestimmung der weiteren Werte der Matrix-Vektor-Multiplikation (i > 0) */
  for( i = 2; i < dim-1; i += 2 ){
    covd = &icov[i*dim];
    covd2 = &icov[i*dim+dim];
    xorpd_r2r( xmm6, xmm6 ); /* Ergebnisvektoren xmm6 und xmm7 l�schen */
    movapd_r2r( xmm6, xmm7 );
    for( j = 0; j < dim-1; j += 2 ){ 
      /* Lesen der Differenz zweier Vektoren (m-x) */
      movupd_m2r( *(h+j), xmm0 );
      /* Bestimmung der Elemente */
      movupd_m2r( *(covd+j), xmm1 );
      movupd_m2r( *(covd2+j), xmm2 );
      mulpd_r2r( xmm0, xmm1 );
      mulpd_r2r( xmm0, xmm2 );
      addpd_r2r( xmm1, xmm6 );
      addpd_r2r( xmm2, xmm7 );
    }
    movapd_r2r( xmm6, xmm0 );
    movlhps_r2r( xmm7, xmm6 );
    movhlps_r2r( xmm0, xmm7 );
    addpd_r2r( xmm6, xmm7 );
    for( ; j < dim; ++j ){ /* Durchf�hrung nichtparalleler Befehle */
      tsum[0] = covd[j]*h[j];
      tsum[1] = covd2[j]*h[j];
      movupd_m2r( *tsum, xmm0 );
      addpd_r2r( xmm0, xmm7 );
    } 
    /* Vektor-Vektor-Multiplikation */
    movupd_m2r( *(h+i), xmm0 );
    mulpd_r2r( xmm7, xmm0 );
    addpd_r2r( xmm0, xmm3 );
  }
  /* Durchf�hrung nichtparalleler Befehle */
  tsum[0] = 0.0;
  for( ; i < dim; ++i ){
    tsum[1] = 0.0;
    covd = &icov[i*dim];
    for( j = 0; j < dim; ++j ){
      tsum[1] += covd[j]*h[j];      
    }
    tsum[0] += h[i]*tsum[1];
  }
  /* Quersumme vom Ergebnisvektor mm3 */
  movhlps_r2r( xmm3, xmm0 );
  addpd_r2r( xmm0, xmm3 );
  if( dim%2 != 0 ){ /* Durchf�hrung nichtparalleler Befehle */
    movupd_m2r( *tsum, xmm0 );
    addpd_r2r( xmm0, xmm3 );
  }
  movupd_r2m( xmm3, *tsum );
  /* <---- Rainer's code ---- */

  if (tsum[0]<0.0) tsum[0]=0.0;                                                 /* Distance must be non-negative     */
  switch (nMode)                                                                /* Branch by operation mode          */
  {                                                                             /* >>                                */
    case GMMG_MDIST : return tsum[0];                                           /*   Mahalanobis distance            */
    case GMMG_LDENS : return delta[k] - 0.5*tsum[0];                            /*   Logarithmic probability density */
    case GMMG_NLDENS: return -(delta[k] - 0.5*tsum[0]);                         /*   Negative log. prob. density     */
    case GMMG_DENS  : return exp(delta[k] - 0.5*tsum[0]);                       /*   Probability density             */
  }                                                                             /* <<                                */
  DLPASSERT(FMSG("Unknown Gauss mode"));                                        /* Invalid value of nMode!           */
  return 0.;                                                                    /* Emergency exit                    */
}
Beispiel #23
0
/* NO JAVADOC
 * Calculates the Mahalanobis distance or the (logarithmic) probability density
 * of a feature vector given a single Gaussian distribution. There are NO CHECKS
 * performed.
 * 
 * Complexity: 2N + N*N where N=m_nDim
 * 
 * @author Rainer Schaffer
 * @param _this
 *          Pointer to GMM instance
 * @param x
 *          Feature vector (expected to have N=m_nDim values
 * @param k
 *          Index of single Gaussian
 * @param nMode
 *          Operation mode, one of the GMMG_XXX constants
 * @return  The (logarithmic) probability density or Mahalanobis distance of x
 *          in single Gaussian k.
 */
float CGmm_GaussF_SSE2(CGmm* _this, float* x, INT32 k, INT16 nMode)
{
  INT32           dim;                                                           /* Feature space dimensionality      */
  float*         icov;                                                          /* Ptr. to inverse covariance matrix */
  float*         h;                                                             /* Ptr. to aux. buffer (2*dim floats)*/
  float*         m;                                                             /* Ptr. to mean vector               */
  short           i = 0, j = 0;                                                  /* (Rainer's variables)              */
  volatile float tsum[4];                                                       /* (Rainer's variables)              */
  register float *covd0, *covd1, *covd2, *covd3;                                /* (Rainer's variables)              */

  dim  = _this->m_nN;                                                           /* Initialize Rainer's varibles      */
  m    = &((float*)CData_XAddr(_this->m_idMean,0,0))[k*dim];                    /* Initialize Rainer's varibles      */
  icov = &((float*)CData_XAddr(_this->m_idSse2Icov,0,0))[k*dim*dim];            /* Initialize Rainer's varibles      */
  h    = (float*)_this->m_lpSse2Buf;                                            /* Initialize Rainer's varibles      */
  if (*(float*)CData_XAddr(_this->m_idCdet,k,0)==0.)                            /* Covariance matrix invalid         */
    return (float)CGmm_GetLimit(_this,nMode);                                   /*   Return limit                    */

  /* ---- Rainer's code ----> */
  if( m == NULL ) 
    return(.0);

  /* Bestimmung der ersten Werte der Matrix-Vektor-Multiplikation (i = 0) */
  covd0 = &icov[0];
  covd1 = &icov[dim];
  covd2 = &icov[2*dim];
  covd3 = &icov[3*dim];
  xorps_r2r( xmm3, xmm3 );  /* Ergebnisvektor xmm3 (Vekt-Vekt-Mult) l�schen */
  movaps_r2r( xmm3, xmm4 ); /* Ergebnisvektor xmm6 (Matr-Vekt-Mult) l�schen */
  movaps_r2r( xmm3, xmm5 ); /* Ergebnisvektor xmm6 (Matr-Vekt-Mult) l�schen */
  movaps_r2r( xmm3, xmm6 ); /* Ergebnisvektor xmm6 (Matr-Vekt-Mult) l�schen */
  movaps_r2r( xmm3, xmm7 ); /* Ergebnisvektor xmm7 (Matr-Vekt-Mult) l�schen */
  for( j = 0; j < dim-3; j += 4 ){ 
    /* Differenz zweier Vektoren (m-x) */
    movups_m2r( *(m+j), xmm0 );
    movups_m2r( *(x+j), xmm1 );
    subps_r2r( xmm1, xmm0 );
    movups_r2m( xmm0, *(h+j) );
    /* Bestimmung der Elemente */
    movups_m2r( *(covd0+j), xmm1 );
    mulps_r2r( xmm0, xmm1 );
    addps_r2r( xmm1, xmm4 ); /* xmm4 = a3, a2, a1, a0 */
    movups_m2r( *(covd1+j), xmm2 );
    mulps_r2r( xmm0, xmm2 );
    addps_r2r( xmm2, xmm5 ); /* xmm5 = b3, b2, b1, b0 */
    movups_m2r( *(covd2+j), xmm1 );
    mulps_r2r( xmm0, xmm1 );
    addps_r2r( xmm1, xmm6 ); /* xmm6 = c3, c2, c1, c0 */
    movups_m2r( *(covd3+j), xmm2 );
    mulps_r2r( xmm0, xmm2 );
    addps_r2r( xmm2, xmm7 ); /* xmm7 = d3, d2, d1, d0 */
  }
  movaps_r2r( xmm4, xmm0 );   /* xmm0 = a3 , a2 , a1 , a0  */
  movlhps_r2r( xmm6, xmm4 );  /* xmm4 = c1 , c0 , a1 , a0  */
  movhlps_r2r( xmm0, xmm6 );  /* xmm6 = c3 , c2 , a3 , a2  */
  addps_r2r( xmm4, xmm6 );    /* xmm6 = c1', c0', a1', a0' */
  movaps_r2r( xmm5, xmm0 );   /* xmm0 = b3 , b2 , b1 , b0  */
  movlhps_r2r( xmm7, xmm5 );  /* xmm5 = d1 , d0 , b1 , b0  */
  movhlps_r2r( xmm0, xmm7 );  /* xmm7 = d3 , d2 , b3 , b2  */
  addps_r2r( xmm5, xmm7 );    /* xmm7 = d1', d0', b1', b0' */
  movaps_r2r( xmm6, xmm1 );   /* xmm1 = c1', c0', a1', a0' */
  unpckhps_r2r( xmm7, xmm6 ); /* xmm6 = d1', c1', d0', c0' */
  unpcklps_r2r( xmm7, xmm1 ); /* xmm1 = b1', a1', b0', a0' */
  movaps_r2r( xmm1, xmm0 );   /* xmm0 = b1', a1', b0', a0' */
  movlhps_r2r( xmm6, xmm1 );  /* xmm1 = d0', c0', b0', a0' */
  movhlps_r2r( xmm0, xmm6 );  /* xmm6 = d1', c1', b1', a1' */
  addps_r2r( xmm1, xmm6 );    /* xmm6 = d* , c* , b* , a*  */
  for( ; j < dim; ++j ){ /* Durchf�hrung nichtparalleler Befehle  */
    h[j] = m[j] - x[j]; 
    tsum[0] = covd0[j]*h[j];
    tsum[1] = covd1[j]*h[j];
    tsum[2] = covd2[j]*h[j];
    tsum[3] = covd3[j]*h[j];
    movups_m2r( *tsum, xmm0 );
    addps_r2r( xmm0, xmm6 );
  } 
  /* Vektor-Vektor-Multiplikation (1. Teil) */
  movups_m2r( *(h), xmm0 );
  mulps_r2r( xmm6, xmm0 );
  addps_r2r( xmm0, xmm3 );

  /* Bestimmung der weiteren Werte der Matrix-Vektor-Multiplikation (i > 0) */
  for( i = 4; i < dim-3; i += 4 ){
    covd0 = &icov[i*dim];
    covd1 = &icov[(i+1)*dim];
    covd2 = &icov[(i+2)*dim];
    covd3 = &icov[(i+3)*dim];
    xorps_r2r( xmm4, xmm4 ); /* Ergebnisvektoren xmm4 bis xmm7 l�schen */
    movaps_r2r( xmm4, xmm5 );
    movaps_r2r( xmm4, xmm6 );
    movaps_r2r( xmm4, xmm7 );
    for( j = 0; j < dim-3; j += 4 ){ 
      /* sum += covd[j] * h[j]; */
      /* Lesen der Differenz zweier Vektoren (m-x) */
      movups_m2r( *(h+j), xmm0 );
      /* Bestimmung der Elemente */
      movups_m2r( *(covd0+j), xmm1 );
      mulps_r2r( xmm0, xmm1 );
      addps_r2r( xmm1, xmm4 ); /* xmm4 = a3, a2, a1, a0 */
      movups_m2r( *(covd1+j), xmm2 );
      mulps_r2r( xmm0, xmm2 );
      addps_r2r( xmm2, xmm5 ); /* xmm5 = b3, b2, b1, b0 */
      movups_m2r( *(covd2+j), xmm1 );
      mulps_r2r( xmm0, xmm1 );
      addps_r2r( xmm1, xmm6 ); /* xmm6 = c3, c2, c1, c0 */
      movups_m2r( *(covd3+j), xmm2 );
      mulps_r2r( xmm0, xmm2 );
      addps_r2r( xmm2, xmm7 ); /* xmm7 = d3, d2, d1, d0 */
    }
    movaps_r2r( xmm4, xmm0 );   /* xmm0 = a3 , a2 , a1 , a0  */
    movlhps_r2r( xmm6, xmm4 );  /* xmm4 = c1 , c0 , a1 , a0  */
    movhlps_r2r( xmm0, xmm6 );  /* xmm6 = c3 , c2 , a3 , a2  */
    addps_r2r( xmm4, xmm6 );    /* xmm6 = c1', c0', a1', a0' */
    movaps_r2r( xmm5, xmm0 );   /* xmm0 = b3 , b2 , b1 , b0  */
    movlhps_r2r( xmm7, xmm5 );  /* xmm5 = d1 , d0 , b1 , b0  */
    movhlps_r2r( xmm0, xmm7 );  /* xmm7 = d3 , d2 , b3 , b2  */
    addps_r2r( xmm5, xmm7 );    /* xmm7 = d1', d0', b1', b0' */
    movaps_r2r( xmm6, xmm1 );   /* xmm1 = c1', c0', a1', a0' */
    unpckhps_r2r( xmm7, xmm6 ); /* xmm6 = d1', c1', d0', c0' */
    unpcklps_r2r( xmm7, xmm1 ); /* xmm1 = b1', a1', b0', a0' */
    movaps_r2r( xmm1, xmm0 );   /* xmm0 = b1', a1', b0', a0' */
    movlhps_r2r( xmm6, xmm1 );  /* xmm1 = d0', c0', b0', a0' */
    movhlps_r2r( xmm0, xmm6 );  /* xmm6 = d1', c1', b1', a1' */
    addps_r2r( xmm1, xmm6 );    /* xmm6 = d* , c* , b* , a*  */
    for( ; j < dim; ++j ){ /* Durchf�hrung nichtparalleler Befehle  */
      h[j] = m[j] - x[j]; 
      tsum[0] = covd0[j]*h[j];
      tsum[1] = covd1[j]*h[j];
      tsum[2] = covd2[j]*h[j];
      tsum[3] = covd3[j]*h[j];
      movups_m2r( *tsum, xmm0 );
      addps_r2r( xmm0, xmm6 );
    } 
    /* Vektor-Vektor-Multiplikation */
    movups_m2r( *(h+i), xmm0 );
    mulps_r2r( xmm6, xmm0 );
    addps_r2r( xmm0, xmm3 );
  }

  /* Durchf�hrung nichtparalleler Befehle */
  tsum[0] = 0.0;
  for( ; i < dim; ++i ){
    tsum[1] = 0.0;
    covd0 = &icov[i*dim];
    for( j = 0; j < dim; ++j ){
      tsum[1] += covd0[j]*h[j];      
    }
    tsum[0] += h[i]*tsum[1];
  }

  /* Quersumme vom Ergebnisvektor mm3 */
  movhlps_r2r( xmm3, xmm0 );
  addps_r2r( xmm0, xmm3 );
  unpcklps_r2r( xmm3, xmm3 );
  movhlps_r2r( xmm3, xmm0 );
  addps_r2r( xmm0, xmm3 );  
  if( dim%4 != 0 ){ /* Durchf�hrung nichtparalleler Befehle */
    movups_m2r( *tsum, xmm0 );
    addps_r2r( xmm0, xmm3 );
  }
  movups_r2m( xmm3, *tsum );
  /* <---- Rainer's code ---- */

  if (tsum[0]<0.0) tsum[0]=0.0;                                                 /* Distance must be non-negative     */
  switch (nMode)                                                                /* Branch by operation mode          */
  {                                                                             /* >>                                */
    case GMMG_MDIST : return tsum[0];                                           /*   Mahalanobis distance            */
    case GMMG_LDENS : return delta[k] - 0.5*tsum[0];                            /*   Logarithmic probability density */
    case GMMG_NLDENS: return -(delta[k] - 0.5*tsum[0]);                         /*   Negative log. prob. density     */
    case GMMG_DENS  : return exp(delta[k] - 0.5*tsum[0]);                       /*   Probability density             */
  }                                                                             /* <<                                */
  DLPASSERT(FMSG("Unknown Gauss mode"));                                        /* Invalid value of nMode!           */
  return 0.;                                                                    /* Emergency exit                    */
}
Beispiel #24
0
void FTP::SaveList(FP_SizeItemList* il)
{
	LPCSTR m;

	if((m=GetOtherPath(Opt.sli.path)) != NULL)
	{
		SayOutError(m);
		return;
	}

	strcat(Opt.sli.path,"ftplist.lst");

	if(!AskSaveList(&Opt.sli))
		return;

	FILE *f = fopen(Opt.sli.path, Opt.sli.Append ? "a" : "w");

	if(!f)
	{
		SayOutError(FMSG(MFLErrCReate),FMSG_ERRORTYPE);
		return;
	}

	PluginPanelItem* p;
	int              n;
	int              level;
	char             str[1024+2],
	   BasePath[1024+2],
	   CurrentUrlPath[1024+2];
	CurrentUrlPath[0] = 0;
	_snprintf(BasePath, ARRAYSIZE(BasePath),
	          "%s%s%s%s",
	          Opt.sli.AddPrefix ? "ftp://" : "",
	          Opt.sli.AddPasswordAndUser ? Message("%s:%s@",hConnect->UserName,hConnect->UserPassword) : "",
	          hConnect->hostname,
	          hConnect->CurDir.c_str());
	AddEndSlash(BasePath,'/',ARRAYSIZE(BasePath));

	if(Opt.sli.ListType == sltTree)
		fprintf(f,"BASE: \"%s\"\n",BasePath);

	for(n = 0; n < il->Count(); n++)
	{
		p = il->Item(n);

		if(p->FindData.dwReserved1 == MAX_DWORD)
			continue;

		//URLS --------------------------------------
		if(Opt.sli.ListType == sltUrlList)
		{
			if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
				continue;

			FixFTPSlash(FTP_FILENAME(p));
			_snprintf(str,ARRAYSIZE(str),"%s%s",BasePath,FTP_FILENAME(p));

			if(Opt.sli.Quote) QuoteStr(str);

			fprintf(f,"%s\n",str);
		}
		else

			//TREE --------------------------------------
			if(Opt.sli.ListType == sltTree)
			{
				StrCpy(str, FTP_FILENAME(p), ARRAYSIZE(str));
				FixFTPSlash(str);

				for(m = str,level = 0;
				        (m=strchr(m,'/')) != NULL;
				        m++,level++);

				fprintf(f,"%*c", level*2+2, ' ');
				m = strrchr(str,'/');

				if(m) m++;
				else m = str;

				fprintf(f,"%c%s",
				        IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY) ? '/' : ' ', m);

				if(Opt.sli.Size)
				{
					level = Max(1, Opt.sli.RightBound - 10 - level*2 - 2 - 1 - (int)strlen(m));
					fprintf(f,"%*c",level,' ');

					if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
						fprintf(f,"<DIR>");
					else
						fprintf(f,"%10I64u", ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow);
				}

				fprintf(f,"\n");
			}
			else

				//GROUPS ------------------------------------
				if(Opt.sli.ListType == sltGroup)
				{
					if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
						continue;

					FixFTPSlash(FTP_FILENAME(p));
					_snprintf(str, ARRAYSIZE(str), "%s%s", BasePath, FTP_FILENAME(p));

					if(!IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY))
						*strrchr(str,'/') = 0;

					if(StrCmp(CurrentUrlPath,str,-1,FALSE) != 0)
					{
						StrCpy(CurrentUrlPath, str, ARRAYSIZE(CurrentUrlPath));
						fprintf(f,"\n[%s]\n", CurrentUrlPath);
					}

					StrCpy(str, FTP_FILENAME(p), ARRAYSIZE(str));
					FixFTPSlash(str);
					m = strrchr(str,'/');

					if(m) m++;
					else m = str;

					fprintf(f," %s", m);

					if(Opt.sli.Size)
					{
						level = Max(1, Opt.sli.RightBound - 10 - (int)strlen(m) - 1);
						fprintf(f,"%*c%10I64u",
						        level,' ',
						        ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow);
					}

					fprintf(f,"\n");
				}
	}

	fclose(f);
	LPCSTR itms[] = { FMSG(MFLDoneTitle), FMSG(MFLFile), Opt.sli.path, FMSG(MFLDone), FMSG(MOk) };
	FMessage(FMSG_LEFTALIGN,NULL,itms,5,1);
}
Beispiel #25
0
#include <all_far.h>
#pragma hdrstop

#include "Int.h"

int FTP::GetHostFiles(struct PluginPanelItem *PanelItem,int ItemsNumber,int Move,String& DestPath,int OpMode)
{
	PROC(("FTP::GetHostFiles","%d [%s] %s %08X",ItemsNumber,DestPath.c_str(),Move?"MOVE":"COPY",OpMode))
	InitDialogItem InitItems[]=
	{
		{DI_DOUBLEBOX, 3, 1,72,6, 0,0,0,0, NULL},
		{DI_TEXT,5, 2,0,0,0,0,0,0,   NULL},
		{DI_EDIT,5, 3,70, 3,0,0,0,0,NULL},
		{DI_TEXT,3, 4,3, 4,0,0,DIF_BOXCOLOR|DIF_SEPARATOR,0,NULL },
		{DI_BUTTON,0, 5,0,0,0,0,DIF_CENTERGROUP,  1, FMSG(MCopy)},
		{DI_BUTTON,0, 5,0,0,0,0,DIF_CENTERGROUP, 0,  FMSG(MCancel)},
	};
	FarDialogItem    DialogItems[ARRAYSIZE(InitItems)];
	FP_SizeItemList  il;

	if(!IS_SILENT(OpMode))
	{
		if(Move)
		{
			InitItems[0].Data = FMSG(MMoveHostTitle);
			InitItems[1].Data = FMSG(MMoveHostTo);
		}
		else
		{
			InitItems[0].Data = FMSG(MCopyHostTitle);
			InitItems[1].Data = FMSG(MCopyHostTo);
Beispiel #26
0
void Connection::recvrequestINT(char *cmd, char *local, char *remote, const char *mode)
{
	int              oldtype = 0,
	                 is_retr;
	FHandle          fout;
	SOCKET           din = INVALID_SOCKET;
	int              ocode, oecode;
	BOOL             oldBrk = FtpSetBreakable(this, -1);
	FTPCurrentStates oState = CurrentState;
	FTNNotify        ni;

	if(type == TYPE_A)
		restart_point = 0;

	ni.Upload       = FALSE;
	ni.Starting     = TRUE;
	ni.Success      = TRUE;
	ni.RestartPoint = restart_point;
	ni.Port         = ntohs(portnum);
	ni.Password[0] = 0; //StrCpy( ni.Password,   UserPassword, ARRAYSIZE(ni.Password));
	StrCpy(ni.User,       UserName, ARRAYSIZE(ni.User));
	StrCpy(ni.HostName,   hostname, ARRAYSIZE(ni.HostName));
	StrCpy(ni.LocalFile,  local, ARRAYSIZE(ni.LocalFile));
	StrCpy(ni.RemoteFile, remote, ARRAYSIZE(ni.RemoteFile));

	if(local[0] == '-' && local[1] == 0)
	{
		;
	}
	else
	{
		fout.Handle = Fopen(local, mode, Opt.SetHiddenOnAbort ? FILE_ATTRIBUTE_HIDDEN : FILE_ATTRIBUTE_NORMAL);

		if(!fout.Handle)
		{
			ErrorCode = GetLastError();
			SysError = TRUE;
			Log(("!Fopen [%s] %s",mode,__WINError()));

			if(!ConnectMessage(MErrorOpenFile,local,-MRetry))
				ErrorCode = ERROR_CANCELLED;

			//goto abort;
			return;
		}

		Log(("recv file [%d] \"%s\"=%p",Host.IOBuffSize,local,fout.Handle));

		if(restart_point != -1)
		{
			if(!Fmove(fout.Handle,restart_point))
			{
				ErrorCode = GetLastError();
				SysError = TRUE;

				if(!ConnectMessage(MErrorPosition,local,-MRetry))
					ErrorCode = ERROR_CANCELLED;

				return;
			}
		}

		TrafficInfo->Resume(restart_point == -1 ? 0 : restart_point);
	}

	is_retr = StrCmp(cmd,Opt.cmdRetr) == 0;

	if(proxy && is_retr)
	{
		proxtrans(cmd, local, remote);
		return;
	}

	if(!initconn())
	{
		Log(("!initconn"));
		return;
	}

	if(!is_retr)
	{
		if(type != TYPE_A)
		{
			oldtype = type;
			setascii();
		}
	}
	else if(restart_point)
	{
		if(!ResumeSupport)
		{
			AddCmdLine(FMSG(MResumeRestart));
			restart_point = 0;
		}
		else if(restart_point != -1)
		{
			if(command("%s %I64u",Opt.cmdRest,restart_point) != RPL_CONTINUE)
			{
				Log(("!restart SIZE"));
				return;
			}
		}
	}

	if(Host.PassiveMode)
	{
		din = dataconn();

		if(din == INVALID_SOCKET)
		{
			Log(("!dataconn: PASV ent"));
			goto abort;
		}
	}

	if(remote)
	{
		if(command("%s %s", cmd, remote) != RPL_PRELIM)
		{
			if(oldtype)
				SetType(oldtype);

			Log(("!command [%s]",cmd));
			fout.Close();

			if(Fsize(local))
				DeleteFile(local);

			return;
		}
	}
	else if(command("%s", cmd) != RPL_PRELIM)
	{
		if(oldtype)
			SetType(oldtype);

		return;
	}

	if(!Host.PassiveMode)
	{
		din = dataconn();

		if(din == INVALID_SOCKET)
		{
			Log(("!dataconn: PASV ret"));
			goto abort;
		}
	}

	/**/

	switch(type)
	{
		case TYPE_A:
		case TYPE_I:
		case TYPE_L:
		{
			FtpSetBreakable(this, FALSE);
			CurrentState = fcsProcessFile;

			if(fout.Handle && PluginAvailable(PLUGIN_NOTIFY))
				FTPNotify().Notify(&ni);

			DWORD b,e,bw;
			__int64 totalValue;
			int b_done;
			DWORD ind;
			int b_ost = Host.IOBuffSize, wsz = get_cluster_size(local)*2;

			if(!wsz || (wsz > b_ost && (wsz /= 2) > b_ost)) wsz = 512;

			ind = Min(1024*1024, Max(4*wsz, 256*1024));  // 256K - 1M
			setsockopt(din, SOL_SOCKET, SO_RCVBUF, (char*)&ind, sizeof(ind));
			b_done = ind = 0;
			totalValue = 0;
			bool unalign = false;
			GET_TIME(b);
			bw = b;

			while(true)
			{
				int c;

				if(wsz != 512 && b_done >= wsz)       // pseudo ansync io
				{
					DWORD off = 0, rdy = 0, ost = b_done % wsz, top = b_done - ost;

					while(ioctlsocket(din, FIONREAD, &rdy) && !rdy)
					{
						if(Fwrite(fout.Handle,IOBuff+off,wsz) != wsz) goto write_error;

						if((off += wsz) >= top) break;
					}

					if(off)
					{
						b_done -= off;

						if(b_done) memmove(IOBuff, IOBuff+off, b_done);

						b_ost = Host.IOBuffSize - b_done;
					}
				}

				//Recv
				c = nb_recv(&din, IOBuff+b_done, b_ost, 0);

				if(c <= 0)
				{
					if(b_done && Fwrite(fout.Handle,IOBuff,b_done) != b_done) goto write_error;

					if(c < 0)
					{
						Log(("gf(%d,%s)=%I64u: !read buff",code,GetSocketErrorSTR(),totalValue));
						code = RPL_TRANSFERERROR;
						goto NormExit;
					}

					Log(("gf(%d,%s)=%I64u: read zero",code,GetSocketErrorSTR(),totalValue));
					break;
				}

				totalValue += c;
				GET_TIME(e);

				if(!fout.Handle)
				{
					//Add readed to buffer
					Log(("AddOutput: +%d bytes", c));
					AddOutput((BYTE*)IOBuff,c);
				}
				else      //Write to file
				{
					b_done += c;
					b_ost -= c;

					if(b_ost < wsz || CMP_TIME(e,bw) >= 3.0)
					{
						DWORD ost = 0;

						if(wsz == 512 || b_done <= wsz)    // timeout or very small buffer
						{
							if(Fwrite(fout.Handle,IOBuff,b_done) != b_done) goto write_error;

							if(b_done < wsz) unalign = true;  // flag of timeout witing (optimize)
						}
						else
						{
							// scatter-gatter for RAID in win32 is very bad on large buffer
							// and when work without RAID synchronous write speed is independ
							// if buffer size is >= 2*cluster size
							int off = 0;

							if(unalign)    // was 'timeouted unaligned write'
							{
								unalign = false;
								off = (DWORD)(totalValue % wsz);

								if(off)
								{
									if(Fwrite(fout.Handle,IOBuff,off) != off) goto write_error;

									b_done -= off;

									if(b_done < wsz)
									{
										memmove(IOBuff, IOBuff+off, b_done);
										goto skip_sg;
									}
								}
							}

							ost = b_done % wsz;
							b_done -= ost;

							do
								if(Fwrite(fout.Handle,IOBuff+off,wsz) != wsz) goto write_error;

							while((off += wsz) < b_done);

							if(ost) memmove(IOBuff, IOBuff+off, ost);
						}

						b_done = ost;
skip_sg:
						b_ost = Host.IOBuffSize - b_done;
						GET_TIME(e);
						bw = e;
					}
				}

				ind += c;

				if(CMP_TIME(e,b) >= 0.5)
				{
					b = e;
					c = ind;
					ind = 0;

					//Call user CB
					if(IOCallback)
					{
						if(!TrafficInfo->Callback(c))
						{
							Log(("gf: canceled by CB"));
do_cancel:
							ErrorCode = ERROR_CANCELLED;

							if(b_done && Fwrite(fout.Handle,IOBuff,b_done) != b_done)
							{
write_error:
								SysError = TRUE;
								ErrorCode = GetLastError();

								if(ErrorCode == ERROR_SUCCESS)
									ErrorCode = ERROR_WRITE_FAULT;  // for non equal counter

								Log(("!write local"));
							}

							goto abort;
						}
					}
					else

						//Show Quite progressing
						if(Opt.ShowIdle && !remote)
						{
							char   digit[ 20 ];
							String str;
							str.printf("%s%s ", FP_GetMsg(MReaded), FCps(digit,(double)totalValue));
							SetLastError(ERROR_SUCCESS);
							IdleMessage(str.c_str(),Opt.ProcessColor);

							if(CheckForEsc(FALSE)) goto do_cancel;
						}
				}
			}

			if(IOCallback)
				TrafficInfo->Callback(0);

			break;
		}
	}

NormExit:
	FtpSetBreakable(this, oldBrk);
	ocode              = code;
	oecode             = ErrorCode;
	CurrentState       = oState;
	scClose(data_peer,-1);

	if(getreply(FALSE) == RPL_ERROR ||
	        oldtype && !SetType(oldtype))
	{
		lostpeer();
	}
	else
	{
		code      = ocode;
		ErrorCode = oecode;
	}

	if(fout.Handle && PluginAvailable(PLUGIN_NOTIFY))
	{
		ni.Starting = FALSE;
		ni.Success  = TRUE;
		FTPNotify().Notify(&ni);
	}

	return;
abort:
	FtpSetBreakable(this, oldBrk);

	if(!cpend)
	{
		Log(("!!!cpend"));
	}

	ocode        = code;
	oecode       = ErrorCode;
	CurrentState = oState;

	if(!SendAbort(din) ||
	        (oldtype && !SetType(oldtype)))
		lostpeer();
	else
	{
		code      = ocode;
		ErrorCode = oecode;
	}

	scClose(data_peer,-1);

	if(fout.Handle && PluginAvailable(PLUGIN_NOTIFY))
	{
		ni.Starting = FALSE;
		ni.Success  = FALSE;
		FTPNotify().Notify(&ni);
	}

	return;
}
Beispiel #27
0
void SayOutError(LPCSTR m,int tp = 0)
{
	LPCSTR itms[] = { FMSG(MFLErrCReate), NULL, FMSG(MOk) };
	itms[1] = m;
	FMessage(tp + FMSG_WARNING,NULL,itms,3,1);
}
Beispiel #28
0
GMM_FTYPE CGmm_GaussD(CGmm* _this, GMM_FTYPE* x, INT32 k, INT16 nMode)
#endif
{
  INT32       i      = 0;                                                       /* Triangular inv. cov. matrix cntr. */
  INT32       n      = 0;                                                       /* Feature vector comp. loop index   */
  INT32       m      = 0;                                                       /* Feature vector comp. loop index   */
  INT32       c      = 0;                                                       /* Covariance matrix index           */
  INT32       N      = 0;                                                       /* Feature dimensionality            */
  INT32       K      = 0;                                                       /* Number of Gaussians               */
  GMM_FTYPE  nTermB = 0.;                                                       /* Term (B), see manual              */
  GMM_FTYPE  nTermE = 0.;                                                       /* Term (E), see manual              */
  GMM_FTYPE  nTermC = 0.;                                                       /* Term (D), see manual              */
  GMM_FTYPE  nSum   = 0.;                                                       /* Sum up buffer                     */
  GMM_FTYPE  nMdist = 0.;                                                       /* Mahalanobis distance              */
  GMM_FTYPE* bk     = NULL;                                                     /* Address of beta[k,0]              */
  GMM_FTYPE* Ik     = NULL;                                                     /* Address of I[k,0]                 */
  GMM_FTYPE* Vk     = NULL;                                                     /* Address of V[k,0]                 */
  INT32*      cmap   = NULL;                                                    /* Covariance tying map              */

  N    = _this->m_nN;                                                           /* Get feature dimensionality        */
  K    = _this->m_nK;                                                           /* Get feature dimensionality        */
  bk   = &beta[k*N];                                                            /* Class dependent beta vector       */
  Ik   = I?I[k]:NULL;                                                           /* Class dep. inv. covariance matrix */
  Vk   = V[k];                                                                  /* Class dep. inv. variance vector   */
  cmap =_this->m_idCmap?(INT32*)CDATA_XADDR(AS(CData,_this->m_idCmap),0,0):NULL;/* Get covariance tying map          */
  if (Ik && *(GMM_FTYPE*)CDATA_XADDR(AS(CData,_this->m_idCdet),k,0)==0.)        /* Covariance matrix invalid         */
    return (GMM_FTYPE)CGmm_GetLimit(_this,nMode);                               /*   Return limit                    */
  if(!_this->m_nLDL)                                                            /* No LDL factorization used         */
  {                                                                             /* >>                                */
    for (n=0; n<N; n++)                                                         /*   Loop over feature vector comps. */
    {                                                                           /*   >>                              */
      nTermB += bk[n]*x[n];                                                     /*     Sum up term B                 */
      nTermE += Vk[n]*x[n]*x[n];                                                /*     Sum up term E                 */
    }                                                                           /*   <<                              */
    if (Ik)                                                                     /*   Have full covariance matrix?    */
    {                                                                           /*   >> YES                          */
#if GMM_FTYPE_CODE == T_FLOAT                                                   /* ## FLOAT ##                       */
      if (gamma && gamma[k]<T_FLOAT_MAX)                                        /*     If already calc'd. this term C*/
#else                                                                           /* ## DOUBLE ##                      */
      if (gamma && gamma[k]<T_DOUBLE_MAX)                                       /*     If already calc'd. this term C*/
#endif                                                                          /* ##                                */
        nTermC = gamma[k];                                                      /*       ... just lazily reuse it    */
      else                                                                      /*     If not yet calc'd. this term C*/
      {                                                                         /*     >>                            */
        for (n=0,i=0; n<N-1; n++)                                               /*       Loop over upper right triang*/
        {                                                                       /*       >>                          */
          for (m=n+1,nSum=0.; m<N; m++,i++) nSum += Ik[i]*x[m];                 /*         L.o.u.r.t and sum up      */
          nTermC += nSum*x[n];                                                  /*         Sum up term C             */
        }                                                                       /*       <<                          */
        if (gamma)                                                              /*       Lazy mode -> remember C term*/
        {                                                                       /*       >>                          */
          c = cmap[k];                                                          /*         Get cov. matrix Gaussian k*/
          for (i=0; i<K; i++)                                                   /*         Loop over cov. tying map  */
            if (cmap[i]==c)                                                     /*           i shares Gaussian c?    */
              gamma[i]=nTermC;                                                  /*             So it has same gamma  */
        }                                                                       /*       <<                          */
      }                                                                         /*     <<                            */
    }                                                                           /*   << (otherwise nTermC=0!         */
    nMdist = alpha[k] - 2.0*nTermB + nTermE + 2.0*nTermC;                       /*   Calculate Mahalanobis distance  */
  }                                                                             /* <<                                */
  else                                                                          /* LDL factorization used            */
  {                                                                             /* >>                                */
    Ik=((GMM_FTYPE *)_this->m_lpLdlL)+k*N*(N-1)/2;                              /*   Get first index of L matrix     */
    Vk=((GMM_FTYPE *)_this->m_lpLdlD)+k*N;                                      /*   Get first index of D vector     */
    for(n=0;n<N;n++,Vk++)                                                       /*   Loop over feature vector comps. */
    {                                                                           /*   >>                              */
#if GMM_FTYPE_CODE == T_FLOAT                                                   /* ## FLOAT ##                       */
      if (gamma && gamma[k]<T_FLOAT_MAX)                                        /*     If already calc'd. this sum   */
#else                                                                           /* ## DOUBLE ##                      */
      if (gamma && gamma[k]<T_DOUBLE_MAX)                                       /*     If already calc'd. this sum   */
#endif                                                                          /* ##                                */
        nSum=gamma[k];                                                          /*       ... just lazily reuse it    */
      else                                                                      /*     If not yet calc'd. this sum   */
      {                                                                         /*     >>                            */
        for(nSum=x[n],m=n+1;m<N;m++,Ik++) nSum+=Ik[0]*x[m];                     /*       Calculate sum               */
        if(gamma)                                                               /*       Lazy mode -> remember sum   */
        {                                                                       /*       >>                          */
          c=cmap[k];                                                            /*         Get cov. matrix Guassian k*/
          for(i=0;i<K;i++) if(cmap[i]==c) gamma[i]=nSum;                        /*         Set values to remember    */
        }                                                                       /*       <<                          */
      }                                                                         /*     <<                            */
      nSum-=bk[n];                                                              /*     Subtract beta                 */
      nMdist+=nSum*nSum*Vk[0];                                                  /*     Update Mahalanobis distance   */
    }                                                                           /*   <<                              */
  }                                                                             /* <<                                */

  if (nMdist<0.) nMdist = 0.;                                                   /* Must be non-negative              */
  switch (nMode)                                                                /* Branch by operation mode          */
  {                                                                             /* >>                                */
    case GMMG_MDIST : return nMdist;                                            /*   Mahalanobis distance            */
    case GMMG_LDENS : return delta[k] - 0.5*nMdist;                             /*   Logarithmic probability density */
    case GMMG_NLDENS: return -(delta[k] - 0.5*nMdist);                          /*   Negative log. prob. density     */
    case GMMG_DENS  : return exp(delta[k] - 0.5*nMdist);                        /*   Probability density             */
  }                                                                             /* <<                                */
  DLPASSERT(FMSG("Unknown Gauss mode"));                                        /* Invalid value of nMode!           */
  return 0.;                                                                    /* Emergency exit                    */
}
Beispiel #29
0
/**
 * Import and export of non-native file formats.
 *
 * @param _this       This instance.
 * @param sFilename   Name of file to import.
 * @param sFilter     Filter to use for import.
 * @param iInst       Instance where to save imported data.
 * @param nMode       Import or export mode.
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 CGEN_PROTECTED CDlpFile_ImportExport
(
  CDlpFile*   _this,
  const char* sFilename,
  const char* sFilter,
  CDlpObject* iInst,
  INT16 nMode
)
{
  INT16    retVal     = O_K;
  lnode_t* lpNode     = NULL;
  CFILE_FTYPE* lpType = NULL;
  FILE* lpFile        = NULL;
  char lpsFilenameLoc[L_PATH];
  char lpsCmd[L_PATH*2];

  CHECK_THIS_RV(FALSE);

  if(!dlp_strlen(sFilename)) return IERROR(_this,FIL_FILENAME,0     ,0,0);
  if(!iInst                ) return IERROR(_this,ERR_NULLARG,"iInst",0,0);

  dlp_strcpy(lpsFilenameLoc,sFilename);

  /* create target directory if necessary */
  if(nMode==EXPORT_FILE)
  {
    char lpNewDir[L_PATH] = "";
    char lpCurDir[L_PATH] = "";

#ifndef __TMS
    if(!_this->m_bExecute)
    {
      if(getcwd(lpCurDir,L_PATH) == NULL) return IERROR(_this,ERR_GETCWD,0,0,0);
      dlp_splitpath(lpsFilenameLoc,lpNewDir,NULL);
      if(0<dlp_strlen(lpNewDir))
      {
        if(dlp_chdir(lpNewDir,TRUE))
        {
          dlp_chdir(lpCurDir,FALSE);
          return
          IERROR(_this,ERR_FILEOPEN,lpsFilenameLoc,
              "writing (failed to create directory)",0);
        }
        dlp_chdir(lpCurDir,FALSE);
      }
    }
#endif
  }

#ifndef __TMS
  /* Execute lpsFilenameLoc (initialization & execute if import) */
  if(_this->m_bExecute)
  {
    char lpsBase[L_PATH];
    char *lpsTmp;
    dlp_splitpath(lpsFilenameLoc,NULL,lpsBase);
    if(strchr(lpsBase,' ')) *strchr(lpsBase,' ')='\0';
    lpsTmp=dlp_tempnam(NULL,lpsBase);
    snprintf(lpsCmd, L_PATH*2-1, "%s %c %s", lpsFilenameLoc, nMode==EXPORT_FILE?'<':'>', lpsTmp);
    dlp_strcpy(lpsFilenameLoc,lpsTmp);
    if(nMode==IMPORT_FILE) if(dlp_system(lpsCmd)!=0) return IERROR(_this,ERR_FILEOPEN,lpsCmd,"executing",0);
  }
#endif

  /* test if file is readable/writable */
  if(nMode==IMPORT_FILE)
    lpFile = fopen(lpsFilenameLoc,"r");
  else if(nMode==EXPORT_FILE)
    lpFile = fopen(lpsFilenameLoc,"a");
  else DLPASSERT(FMSG("Unknown operation mode."));

  if(!lpFile)
  {
    if (nMode==IMPORT_FILE)
      return IERROR(_this,ERR_FILEOPEN,sFilename,"reading",0);
    else if (nMode==EXPORT_FILE)
      return IERROR(_this,ERR_FILEOPEN,sFilename,"writing",0);
  }
  fclose(lpFile);

  /* lookup filter function from list */
  lpType = (CFILE_FTYPE*)dlp_calloc(1,sizeof(CFILE_FTYPE));
  if(!lpType) return IERROR(_this,ERR_NOMEM,0,0,0);

  dlp_strncpy(lpType->lpName,sFilter,L_NAMES);
  dlp_strncpy(lpType->lpClassName,iInst->m_lpClassName,L_NAMES);
  lpType->nMode = nMode;

  lpNode = list_find(_this->m_lpFtypes,lpType,CDlpFile_CompareFTypeList);
  if(!lpNode)
  {
    dlp_free(lpType);
    return
      IERROR(_this,FIL_NOIMEX,nMode==IMPORT_FILE?"import":"export",sFilter,
        iInst->m_lpClassName);
  }
  dlp_free(lpType);
  lpType = NULL;

  /* Invoke import function */
  lpType = (CFILE_FTYPE*)lnode_get(lpNode);
  retVal = lpType->FilterFunc(_this,lpsFilenameLoc,iInst,lpType->lpName);

#ifndef __TMS
  /* Execute lpsFilenameLoc (execute if export & finalization) */
  if(_this->m_bExecute)
  {
    if(nMode==EXPORT_FILE) dlp_system(lpsCmd);
    unlink(lpsFilenameLoc);
  }else
#endif
  if(nMode==EXPORT_FILE && _this->m_bZip) dlp_fzip(lpsFilenameLoc,"wb6");

  if(retVal != O_K)
  {
    if(nMode==IMPORT_FILE) return IERROR(_this,FIL_IMPORT,lpsFilenameLoc,sFilter,0);
    else                   return IERROR(_this,FIL_EXPORT,lpsFilenameLoc,sFilter,0);
  }

  return O_K;
}
Beispiel #30
0
/*
 * Manual page at function.def
 */
INT16 CGEN_PUBLIC CFunction::OnSet()
{
  // Delegate to running function                                               // ------------------------------------
  FNC_DELEGATE OnSet();                                                         // Use a weird macro (see function.def)

  // Initialize                                                                 // ------------------------------------
  const char* lpsId = GetNextToken(TRUE);                                       // Determine field name
  CDlpObject* iCont = GetActiveInstance();                                      // Get first instance argument
  if (m_nStackLen<=0)                                                           // Stack is to contain the new value
    return IERROR(this,FNC_STACKUNDERFLOW," on method ","-set",0);              // |
  if (m_aStack[0].nType==T_INSTANCE && m_aStack[0].val.i==iCont) PopInstance(1);// Pop the active instance

  // Validate                                                                   // ------------------------------------
  if (!dlp_strlen(lpsId))                                                       // If no field name committed
    return IERROR(this,FNC_EXPECT,"field identifier after -set",0,0);           //   Error
  SWord* lpWrd = iCont->FindWord(lpsId,WL_TYPE_FIELD);                          // Find field in container
  if (!lpWrd)                                                                   // If not found
  {                                                                             // >>
    iCont = this;                                                               //   Use this instance as container
    lpWrd = FindWord(lpsId,WL_TYPE_FIELD);                                      //   And seek again
  }                                                                             // <<
  if (!lpWrd                  ) return IERROR(this,ERR_NOTFIELD,lpsId,0,0);     // If still not found --> error
  if (lpWrd->nFlags & FF_NOSET) return IERROR(this,FNC_NOSET   ,lpsId,0,0);     // If write-protected --> error

  // Set new value                                                              // ------------------------------------
  switch (lpWrd->ex.fld.nType)                                                  // Branch for field variable type
  {                                                                             // >>
    case T_BOOL    : {      BOOL bTmp=(   BOOL)PopLogic(2);   iCont->SetField(lpWrd,(void*)&bTmp); } break;// - Boolean
    case T_UCHAR   : {     UINT8 nTmp=(  UINT8)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Unsigned character
    case T_CHAR    : {      INT8 nTmp=(   INT8)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Signed character
    case T_USHORT  : {    UINT16 nTmp=( UINT16)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Unsigned short integer
    case T_SHORT   : {     INT16 nTmp=(  INT16)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Signed short integer
    case T_UINT    : {    UINT32 nTmp=( UINT32)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Unsigned integer
    case T_INT     : {     INT32 nTmp=(  INT32)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Signed integer
    case T_ULONG   : {    UINT64 nTmp=( UINT64)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Unsigned long integer
    case T_LONG    : {     INT64 nTmp=(  INT64)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Signed long integer
    case T_FLOAT   : {   FLOAT32 nTmp=(FLOAT32)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Single precision floating point
    case T_DOUBLE  : {   FLOAT64 nTmp=(FLOAT64)PopNumber(2).x;iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Double precision floating point
    case T_COMPLEX : { COMPLEX64 nTmp=         PopNumber(2);  iCont->SetField(lpWrd,(void*)&nTmp); } break;// - Double precision complex floating point
    case T_TEXT    : /* Fall through */                                                                    // - Text (depreciated type!)
    case T_CSTRING : /* Fall through */                                                                    // - Constant string
    case T_STRING  : {   char* lpsTmp =        PopString(2);  iCont->SetField(lpWrd,(void*)&lpsTmp);}break;// - String
    case T_INSTANCE:                                                            // - Instance
    {                                                                           //   >>
      CDlpObject* iVal = PopInstance(2);                                        //     Get new value
      if                                                                        //     Check instance type
      (                                                                         //     |
        dlp_strlen(lpWrd->ex.fld.lpType)>0     &&                               //     - Typed instance field?
        iVal != NULL                           &&                               //     - New value non-NULL?
        OfKind(lpWrd->ex.fld.lpType,iVal)==NULL                                 //     - Type cast impossible?
      )                                                                         //     |
      {                                                                         //     >>
        return                                                                  //       Error
          IERROR(this,FNC_TYPECAST,0,iVal->m_lpClassName,lpWrd->ex.fld.lpType); //       |
      }                                                                         //     <<
      iCont->SetField(lpWrd,(void*)&iVal);                                      //     Set new value
      break;                                                                    //     .
    }                                                                           //   <<
    default:                                                                    // - Other types
      if (lpWrd->ex.fld.nType>0 && lpWrd->ex.fld.nType<=256) {                  //     Character array?
        char* lpsTmp=PopString(2);                                              //       Set new value
        iCont->SetField(lpWrd,&lpsTmp);                                         //       |
      } else                                                                    //     Type unknown!
        DLPASSERT(FMSG("Unknown field type"));                                  //       Error
  }                                                                             // <<

  return O_K;                                                                   // Done.
}