Ejemplo n.º 1
0
void FString::ReplaceChars (const char *oldcharset, char newchar)
{
	if (oldcharset == NULL || oldcharset[0] == '\0')
		return;

	ReplaceChars([&oldcharset](char c){ return strchr(oldcharset, c) != NULL; }, newchar);
}
Ejemplo n.º 2
0
void Prod(struct TNod *radacina){
	struct TNod* stg = radacina->st;
	struct TNod* drp = radacina->dr;
	
	double start = radacina->start;
	double end = radacina->end;
	
	char variab = radacina->var;

	int i = 0;
	//Iteram de la start la end si prelucram expresia
	double prod = 1;
	for (i=start; i<=end; i++){
		char* rep = malloc(sizeof(char));
		*rep = variab;
		char buffer[20];
		
		snprintf(buffer, 20,"%i",i);

		//Clonez lel
		struct TNod* aux = NULL;
		ClonareArb(radacina,aux);
		

		//Inlcouire variabila cu valoarea lui i
//		#pragma omp parallel
		ReplaceChars(aux, rep, buffer);
		free(rep);
		PrelucrareArbore(aux->dr);
		prod *= *(aux->dr->rez);
	}
	
	//return prod;
	*(radacina->rez) = prod;
}
Ejemplo n.º 3
0
void Notify(HANDLE hContact, TCHAR *text)
{
	if (text != NULL && text[0] == _T('\0'))
		text = NULL;

	if (!opts.track_changes && text != NULL)
		return;

	if (!opts.track_removes && text == NULL)
		return;

	// Replace template with nick
	TCHAR templ[1024];
	lstrcpyn(templ, text == NULL ? opts.template_removed : opts.template_changed, MAX_REGS(templ));
	ReplaceChars(templ);

	TCHAR log[1024];
	mir_sntprintf(log, sizeof(log), templ, 
		text == NULL ? TranslateT("<no nickname>") : text);

	if (opts.history_enable)
		HistoryLog(hContact, log);

	if (opts.popup_enable)
		ShowPopup(hContact, NULL, log);
}
Ejemplo n.º 4
0
void FString::ReplaceChars (char oldchar, char newchar)
{
	if (oldchar == '\0')
		return;

	ReplaceChars([&oldchar](char c){ return c == oldchar; }, newchar);
}
Ejemplo n.º 5
0
void ReplaceChars(struct TNod *lel, char* rep, char* with){
	
	char* a = lel->info;
	
	
	if(strcmp(a, rep)==0){
		memset(lel->info,0,sizeof(lel->info));
		strcpy(lel->info, with);
		
	}else if(strcmp(a,"+")==0 || strcmp(a,"-")==0 || strcmp(a,"*")==0 || strcmp(a,"/")==0 || strcmp(a,"sqrt")==0 || strcmp(a,"pow")==0){
		ReplaceChars(lel->st,rep,with);
		ReplaceChars(lel->dr,rep,with);
	}else if(strcmp(a,"sum")==0 || strcmp(a,"prod")==0){
		ReplaceChars(lel->dr,rep,with);
	}

}
Ejemplo n.º 6
0
std::string PerforceDepotView::EscapeRevisionPaths(const PathList& filePaths, const Revision revision)
{
	std::stringstream escapedPaths;
	for (auto path : filePaths)
	{
		escapedPaths << '"' << ReplaceChars(toPath(path)) << "#" << revision << '"';
	}
	return escapedPaths.str();
}
Ejemplo n.º 7
0
static void visualStudioHitFormat(void* context, const char* filename, unsigned int lineNumber, const char* lineStart, const char* lineEnd)
{
    gHitCount++;
    if (gReplaceSlashesTo)
    {
        std::string s(filename);
        ReplaceChars(s, gReplaceSlashesFrom, gReplaceSlashesTo);
        printf("%s (%d):", s.c_str(), lineNumber);
    }
    else
    {
        std::string s(filename);
        ReplaceChars(s, '/', '\\');
        printf("%s (%d):", s.c_str(), lineNumber);
    }
    printLinePart(lineStart, lineEnd);
    putchar('\n');
}
Ejemplo n.º 8
0
Archivo: zsh.cpp Proyecto: 0xheart0/vlc
static void PrintOption(const module_config_t *item, const std::string &opt,
                        const std::string &excl, const std::string &args)
{
    char *longtext = item->psz_longtext;
    char *text = item->psz_text;
    char i_short = item->i_short;
    ReplaceChars(longtext);
    ReplaceChars(text);

    if (!longtext || strchr(longtext, '\n') || strchr(longtext, '('))
        longtext = text;

    printf("  \"");

    const char *args_c = args.empty() ? "" : "=";
    if (i_short) {
        printf("(-%c", i_short);

        if (!excl.empty())
            printf("%s", excl.c_str());

        printf(")--%s%s[%s]", opt.c_str(), args_c, text);

        if (!args.empty())
            printf(":%s:%s", longtext, args.c_str());

        printf("\"\\\n  \"(--%s%s)-%c", opt.c_str(), excl.c_str(), i_short);
    } else {
        if (!excl.empty())
            printf("(%s)", excl.c_str());
        printf("--%s", opt.c_str());
        if (!excl.empty())
            printf("%s", args_c);
    }

    printf("[%s]", text);
    if (!args.empty())
        printf( ":%s:%s", longtext, args.c_str());
    puts( "\"\\");
}
Ejemplo n.º 9
0
/**************************************************************************
*   Precentiles given as a comma-sep list
*/
void HandleListPercentiles(NUMSTAT *nsPO, DOUB *rvalsPD, int num, FILE *outPF)
{
    char *cPC;
    int p;
    DOUB pD,prsD;

    HAND_NFILE(outPF);
    /***
    *   Read list of comma-delimited percentiles
    */
    ReplaceChars(',',nsPO->prls,' ',nsPO->prls);
    fprintf(outPF,"%s# Percentiles: %s\n", nsPO->echo, nsPO->prls);
    if(nsPO->do_sl) {
        fprintf(outPF,"%sPercentiles",nsPO->echo);
    }
    cPC = nsPO->prls;
    PASS_BLANK(cPC);
    while(ISLINE(*cPC))
    {
        prsD = BAD_D; 
        sscanf(cPC,"%lf",&prsD);
        if(BAD_DOUB(prsD))
        {
            PROBLINE;
            printf("Bad percentile list format\n");
            printf("|%s|\n",nsPO->prls); 
            printf("Here: %s\n",cPC); 
            return;
        }
        if( (prsD<0.0) || (prsD>100.0) )
        {
            PROBLINE;
            printf("Bad percentile value listed\n");
            printf("|%s|\n",nsPO->prls); 
            printf("Bad: %f\n",prsD); 
            return;
        }
        pD = DNUM(nsPO->num) * prsD / 100.0;
        p = ROUND(pD);
        LIMIT_NUM(p, 0, (num - 1));
        ReportSingPercentile(nsPO, p, rvalsPD[p], num, outPF); 
        NEXT_WORD(cPC);
    }
    if(nsPO->do_sl) {
        fprintf(outPF,"\n");
    }
    return;
}
Ejemplo n.º 10
0
static void grepFormatHit(void* context, const char* filename, unsigned int lineNumber, const char* lineStart, const char* lineEnd)
{
    gHitCount++;
    if (gReplaceSlashesTo)
    {
        std::string s(filename);
        ReplaceChars(s, gReplaceSlashesFrom, gReplaceSlashesTo);
        printf("%s:%d:", s.c_str(), lineNumber);
    }
    else
    {
        printf("%s:%d:", filename, lineNumber);
    }
    printLinePart(lineStart, lineEnd);
    putchar('\n');
}
Ejemplo n.º 11
0
static void grepFormatHitTrimmed(void* context, const char* filename, unsigned int lineNumber, const char* lineStart, const char* lineEnd)
{
    char* basepath = (char*)context;
    gHitCount++;
    if (gReplaceSlashesTo)
    {
        std::string s(filename);
        ReplaceChars(s, gReplaceSlashesFrom, gReplaceSlashesTo);
        trimmedPrint(basepath, s.c_str(), lineNumber);
    }
    else
    {
        trimmedPrint(basepath, filename, lineNumber);
    }
    printLinePart(lineStart, lineEnd);
    putchar('\n');
}
Ejemplo n.º 12
0
void Sum(struct TNod *radacina){
	struct TNod* stg = radacina->st;
	struct TNod* drp = radacina->dr;
	
	double start = radacina->start;
	double end = radacina->end;
	
	char variab = radacina->var;
	

	int i = 0;
	//Iteram de la start la end si prelucram expresia
	double sum = 0;
	//#pragma parallel for shared(start,end) private(i,sum) default(none)
	for (i=start; i<=end; i++){
		char* rep = malloc(sizeof(char));
		*rep = variab;
		char buffer[20];
		
		snprintf(buffer, 20,"%i",i);
		
		//Clonez lel
		struct TNod* aux = NULL;
		aux = (TArb)malloc (sizeof(TNod));
			
		ClonareArb(radacina, aux);
		

		//Inlcouire variabila cu valoarea lui i
		
		ReplaceChars(aux, rep, buffer);
		free(rep);
		PrelucrareArbore(aux->dr);
		//printf("arb = %lf\n",*(aux->dr->rez));
		sum += *(aux->dr->rez);
	}
	//return sum;
	//printf("after\n");
	*(radacina->rez) += sum;
	//printf("before %lf\n",*(radacina->rez));
}
Ejemplo n.º 13
0
int HandleFilterBlocksI(FILTER *filtPO)
{
    int i;
    char *cPC;

    if( (filtPO->l_blk < 1) || (filtPO->l_blk > MAX_BLK_SIZE) || (filtPO->l_bof < 0) ) {
        printf("Line block size (%d) and offset (%d) won't work\n", filtPO->l_blk, filtPO->l_bof);
        return(FALSE);
    }
    /***
    *   Within-block masking?
    */
    if( (filtPO->l_blk > 1) && (!NO_S(filtPO->blk_mlis)) ) {
        /*  Allocate mask then parse list and set; 1-based so add 1 extra */
        filtPO->blk_mask = (char *)ALLOC(filtPO->l_blk + 1, sizeof(char));
        ReplaceChars(',', filtPO->blk_mlis, ' ', filtPO->blk_mlis);
        cPC = filtPO->blk_mlis;
        while(ISLINE(*cPC))
        {
            i = -1;
            sscanf(cPC,"%d",&i);
            if(i < 1) {
                printf("Problem with block mask list:\n|%s| |%s| %d\n", filtPO->blk_mlis, cPC, i);
                return(FALSE);
            }
            if(i <= filtPO->l_blk) {
                filtPO->blk_mask[i] = 1;
            }
            NEXT_WORD(cPC);
        }
        /* Invert? */
        if(filtPO->do_bm_not) {
            InvertMask(filtPO->blk_mask, filtPO->l_blk + 1);
        }
    }
    return(TRUE);
}
Ejemplo n.º 14
0
	bool RemoveChars(const std::string& input,
		const base::StringPiece& remove_chars,
		std::string* output) {
		return ReplaceChars(input, remove_chars.as_string(), std::string(), output);
	}
Ejemplo n.º 15
0
/*************************************************************************
*   Scatter plot
*/
int NumstatHandleSplotI(NUMSTAT *nsPO)
{
    int i,r,c,nrow,ncol;
    DOUB fD,sD;
    char labS[DEF_BS],numS[DEF_BS],formS[DEF_BS];
    HISTOGRAM *fhisPO, *shisPO;
    TABLE *tabPO;

    NumlistToHistogramI(nsPO->vals, -1.0, BAD_D, BAD_D, &fhisPO);
    NumlistToHistogramI(nsPO->svals, -1.0, BAD_D, BAD_D, &shisPO);
    ncol = GetHistogramNumBinsI(fhisPO);
    nrow = GetHistogramNumBinsI(shisPO);
    tabPO = CreateTablePO(nrow, ncol);
    if(!tabPO) {
        CHECK_HISTOGRAM(fhisPO); CHECK_HISTOGRAM(shisPO);
        return(FALSE);
    }
    /***
    *   Set lables
    */
    HistogramAutoFormatStringI(fhisPO,formS);
    for(c=0;c<ncol;c++) 
    {
        HistogramValuesForBinI(fhisPO, c, NULL, &fD, NULL);
        sprintf(numS,formS,fD);
        sprintf(labS,"C_%s",numS);
        ReplaceChars(' ',labS,'_',labS);
        SetTableColLabI(tabPO,c,labS);
    }
    HistogramAutoFormatStringI(shisPO,formS);
    for(r=0; r<nrow; r++)
    {
        HistogramValuesForBinI(shisPO, r, NULL, &fD, NULL);
        sprintf(numS,formS,fD);
        sprintf(labS,"Row_%s",numS);
        ReplaceChars(' ',labS,'_',labS);
        /* HAM? Why -2  *
        SetTableRowLabI(tabPO,nrow - r -2,labS);
        */
        SetTableRowLabI(tabPO,nrow - r -1,labS);
    }
    /***
    *   Fill table values
    */
    for(i=0; i<nsPO->num; i++)
    {
        GetNumlistDoubI(nsPO->vals,i,&fD);
        GetNumlistDoubI(nsPO->svals,i,&sD);
        HistogramBinForValueI(fhisPO, fD, &c, NULL,NULL);
        HistogramBinForValueI(shisPO, sD, &r, NULL,NULL);
        /* HAM? Why -2  *
        r = nrow - r - 2;
        */
        r = nrow - r - 1;
        GetTableValI(tabPO,r,c,&fD);
        fD += 1.0;
        SetTableValI(tabPO,r,c,fD);
    }
    fprintf(nsPO->out,"%s#\n",nsPO->echo);
    AutoTableOutFormattingI(tabPO, TRUE, FALSE);
    DumpTable(tabPO,FALSE,FALSE,nsPO->out);
    /***
    *   Clean up 
    */
    CHECK_TABLE(tabPO);
    CHECK_HISTOGRAM(fhisPO); CHECK_HISTOGRAM(shisPO);
    return(TRUE);
}
int EncodeMpiBuff(void* values, MPI_Datatype datatype, int count, 
		 char* sohReplace, char* partitionReplace, char* eotReplace, charList* result)
{
  //flag indicating if any characters where encoded
  int encoded = FALSE;
  
	
	//create a temporary buffer which will be resused to encode the buffer
  charList* tempBuffer = (charList*)malloc(sizeof(charList));;
  InitializeCharList(tempBuffer);

  //Createa string versions of the values to encode
  char* soh = (char*)malloc(2*sizeof(char));
	soh[0] = SOH;
	soh[1] = '\0';

	char* partition = (char*)malloc(2*sizeof(char));
	partition[0] = PARTITION_CHR;
	partition[1] = '\0';	
	
	char* eot = (char*)malloc(2*sizeof(char));
	eot[0] = EOT;
	eot[1] = '\0';

	//Send back the code to decode on the client side	
	char encodeKeys[255];
	memset(encodeKeys, '\0', 255);
			
	int encodeKeyLen = sprintf(encodeKeys, "%c%s%c%s%c%s", PARTITION_CHR, sohReplace, 
			PARTITION_CHR, partitionReplace, PARTITION_CHR, eotReplace);
	AddChars(result, encodeKeys, encodeKeyLen);
	
  int i = 0;	
  for(i=0; i < count; i++)
  {
    char *value;

    int length = 0;
    if(datatype == MPI_CHAR){
      length = asprintf(&value, "%c", ((char*)values)[i]);    
    } else if(datatype == MPI_BYTE || datatype == MPI_UNSIGNED_CHAR){
      length = asprintf(&value, "%c", ((unsigned char*)values)[i]);    
    } else if(datatype == MPI_SHORT){
      length = asprintf(&value, "%hi", ((short*)values)[i]);    
    } else if(datatype == MPI_INT){
      length = asprintf(&value, "%d", ((int*)values)[i]);    
    } else if(datatype == MPI_LONG){
      length = asprintf(&value, "%ld", ((long int*)values)[i]);    
    } else if(datatype == MPI_FLOAT){  
      length = asprintf(&value, "%f", ((float*)values)[i]);
    } else if(datatype == MPI_DOUBLE){
      length = asprintf(&value, "%f", ((double*)values)[i]);  
    } else if(datatype == MPI_UNSIGNED_SHORT){
      length = asprintf(&value, "%hu", ((unsigned short*)values)[i]);   
    } else if(datatype == MPI_UNSIGNED){
      length = asprintf(&value, "%u", ((unsigned int*)values)[i]);   
    } else if(datatype == MPI_UNSIGNED_LONG){
      length = asprintf(&value, "%lu", ((unsigned long*)values)[i]);   
    } else if(datatype == MPI_LONG_DOUBLE){
      length = asprintf(&value, "%Lf", ((long double*)values)[i]);
    }

   	AddChars(tempBuffer, value, length);
    free(value);
    
		if(ReplaceChars(tempBuffer, soh, sohReplace) == TRUE)
			encoded = TRUE;
	
		if(ReplaceChars(tempBuffer, partition, partitionReplace) == TRUE)
			encoded = TRUE;

		if(ReplaceChars(tempBuffer, eot, eotReplace) == TRUE)
			encoded = TRUE;
  
  	AddChars(result, PARTITION_STR, 1);				
		AddChars(result, tempBuffer->Items, tempBuffer->ItemCount);
	
		ClearChars(tempBuffer);
  }
	
	free(soh);
	free(partition);
	free(eot);

	CleanUpCharList(tempBuffer);
	
	return encoded;
}
Ejemplo n.º 17
0
bool CMusikLibrary::RenameFile( CMusikSong & song )
{
	//--------------------------------//
	//--- new filename information ---//
	//--------------------------------//
	
	wxString sPrePath	= song.MetaData.Filename.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR );
	wxString sFile		= wxGetApp().Prefs.sAutoRename;

	wxString sCheck;

	//---------------------------------------------//
	//--- the song's root directory. this will	---//
	//--- only affect us if there is directory	---//
	//--- seperation stuff going on.			---//
	//---------------------------------------------//
	wxString sRootPath = sPrePath;
	if ( wxGetApp().Prefs.sAutoRename.Find( wxFileName::GetPathSeparator() ) > - 1 )
	{
		sRootPath = MusikGetRootPath(song.MetaData.Filename.GetPath());
		if(sRootPath.IsEmpty())
			return false;
	}

	//--------------------------------------------//
	//--- format the output filename (without) ---//
	//--- path. e.g.. 01 - STP - Meat Plow.mp3 ---//
	//--------------------------------------------//

	//----------------------------------------------//
	//--- replace masked values					 ---//
	//----------------------------------------------//
	wxString sForbiddenChars = GetForbiddenChars();
	wxString sTitle = ConvFromUTF8( song.MetaData.Title );
	//--- on some platforms, we can't have certain characters, so blank them out ---//
	ReplaceChars(sTitle,sForbiddenChars);
	if ( !ReplaceMask( &sFile, wxT( "%1" ),sTitle) )
		return false;
	wxString sArtist = ConvFromUTF8( song.MetaData.Artist );
	ReplaceChars(sArtist,sForbiddenChars);
	if ( !ReplaceMask( &sFile, wxT( "%2" ),sArtist) )
		return false;
	wxString sAlbum = ConvFromUTF8( song.MetaData.Album );
	ReplaceChars(sAlbum,sForbiddenChars);
	if ( !ReplaceMask( &sFile, wxT( "%3" ),sAlbum) )
		return false;
	wxString sGenre = ConvFromUTF8( song.MetaData.Genre );
	ReplaceChars(sGenre,sForbiddenChars);
	if ( !ReplaceMask( &sFile, wxT( "%4" ),sGenre) )
		return false;
	wxString sYear = ConvFromUTF8( song.MetaData.Year );
	ReplaceChars(sYear,sForbiddenChars);
	if ( !ReplaceMask( &sFile, wxT( "%5" ),sYear) )
		return false;
	wxString sTrackNum=wxString::Format(wxT("%.2d"), song.MetaData.nTracknum );
	if ( !ReplaceMask( &sFile, wxT( "%6" ), sTrackNum ) )
		return false;

	//--- final name ---//
	wxFileName newfilename;
	newfilename.AssignDir(sRootPath);
	newfilename.SetName(sFile);
	newfilename.SetExt(song.MetaData.Filename.GetExt());
//	newfilename.Normalize();
	//--- filename already the same? return ---//
	if ( song.MetaData.Filename == newfilename )
	{
		return true;
	}

	//-----------------------------------------//
	//--- create needed directories and do	---//
	//--- any sort of filename modification	---//
	//--- that is needed					---//
	//-----------------------------------------//
	if(!wxFileName::Mkdir(newfilename.GetPath(),0777,wxPATH_MKDIR_FULL))
		return false;

	//-----------------------------------------//
	//--- file does need to be renamed, so	---//
	//--- rename it, then return			---//
	//-----------------------------------------//
	if ( wxRenameFile( song.MetaData.Filename.GetFullPath(), newfilename.GetFullPath(),false ) ) // false == no overwrite
	{
		song.MetaData.Filename = newfilename;
        if( m_pDB->Exec(MusikDb::QueryString("update songs set filename =%Q where songid = %d;",
				( const char* )ConvToUTF8( song.MetaData.Filename.GetFullPath() ),
				 song.songid )))
        {
            OnSongDataChange(song.songid);
            return true;
        }
	}
	
	//-----------------------------------------//
	//--- how could we get here? we can't	---//
	//--- so just return false				---//
	//-----------------------------------------//
	return false;
}