Esempio n. 1
0
bool ICmdProcTextEntryStc::DoReplaceAll(ICmdParam& cmd)
{
	cmd.param2=1;

	Target.SetInsertionPoint(0);
	if(!TestSelection() && !DoFind(cmd))
	{
		Wrapper::MsgsDialog(_hT("no results"),0);
		return false;
	}

	int n=0;
	Target.BeginUndoAction();
	try
	{
		while(DoReplace(cmd)) n++;
	}
	catch(std::exception&)
	{
			
	}
	Target.EndUndoAction();
	Wrapper::MsgsDialog(String::Format(_hT("%d results replaced"),n),0);
	return true;
}
Esempio n. 2
0
bool ICmdProcTextEntryStc::DoExecId(ICmdParam& cmd)
{
	switch(cmd.param1)
	{
	case CP_DIRTY:
		Target.MarkDirty();
		break;
	case CP_SAVE_TEMP:
		return true;
	case CP_SAVE_FILE:
		return false;
	case CP_FIND:
		if(data.text_old=="") return false;
		Target.SetSearchFlags(data.flags.val());
		return DoFind(cmd);
	case CP_REPLACE:
		if(data.text_old=="") return false;
		Target.SetSearchFlags(data.flags.val());
		return DoReplace(cmd);
	case CP_REPLACEALL:
		if(data.text_old=="") return false;
		Target.SetSearchFlags(data.flags.val());
		return DoReplaceAll(cmd);
	default:
		return basetype::DoExecId(cmd);
	}
	return true;
}
static bool
CVE_2013_0750_firefox8_0_1_ReplaceRegExpCallback(JSContext *cx, RegExpStatics *res, size_t count, void *p)
{
    ReplaceData &rdata = *static_cast<ReplaceData *>(p);

    rdata.calledBack = true;
    JSLinearString &str = rdata.str->asLinear();  /* flattened for regexp */
    size_t leftoff = rdata.leftIndex;
    const jschar *left = str.chars() + leftoff;
    size_t leftlen = res->matchStart() - leftoff;
    rdata.leftIndex = res->matchLimit();

    size_t replen = 0;  /* silence 'unused' warning */
    if (!FindReplaceLength(cx, res, rdata, &replen))
        return false;

    size_t growth = leftlen + replen;
    if (!rdata.sb.reserve(rdata.sb.length() + growth))
        return false;
    rdata.sb.infallibleAppend(left, leftlen); /* skipped-over portion of the search value */
    DoReplace(cx, res, rdata);
    return true;
}
Esempio n. 4
0
int
main (int argc, char **argv)
{
    FILE	*f;
    ReplaceSet	*s;

    if (!argv[1])
	Bail ("usage: %s <template.sgml>", argv[0]);
    f = fopen (argv[1], "r");
    if (!f)
    {
	Bail ("can't open file %s", argv[1]);
	exit (1);
    }
    while ((s = ReplaceSetRead (stdin)))
    {
	DoReplace (f, s);
	ReplaceSetDispose (s);
	rewind (f);
    }
    if (ferror (stdout))
	Bail ("%s", "error writing output");
    exit (0);
}
Esempio n. 5
0
void SavvyEditor::AppFrame::OnFindDialog(wxFindDialogEvent& a_Event)
{
	wxEventType type = a_Event.GetEventType();

	if (type == wxEVT_FIND || type == wxEVT_FIND_NEXT)
	{
		if (!DoFind(a_Event.GetFindString(), a_Event.GetFlags()))
		{
			wxMessageBox(wxT("No more matches."), DEFAULT_FRAME_TITLE);
		}
	}
	else if (type == wxEVT_FIND_REPLACE)
	{
		if (!DoReplace(a_Event.GetFindString(), a_Event.GetReplaceString(), a_Event.GetFlags()))
		{
			wxMessageBox(wxT("Nothing to replace."), DEFAULT_FRAME_TITLE);
		}
	}
	else if (type == wxEVT_FIND_REPLACE_ALL)
	{
		int numReplaced = DoReplaceAll(a_Event.GetFindString(), a_Event.GetReplaceString(), a_Event.GetFlags());
		if (numReplaced > 0)
		{
			wxString numString = wxString::Format(wxT("%i"), numReplaced);
			numString.Append(" occurrences replaced.");
			wxMessageBox(numString, DEFAULT_FRAME_TITLE);
		}
		else
		{
			wxMessageBox(wxT("Nothing to replace."), DEFAULT_FRAME_TITLE);
		}
	}
	else if (type == wxEVT_FIND_CLOSE)
	{
		wxFindReplaceDialog *dlg = a_Event.GetDialog();

		int idMenu;
		const wxChar *txt;
		if (dlg == m_FindDialog)
		{
			txt = wxT("Find");
			idMenu = ID_FindDialog;
			m_FindDialog = NULL;
		}
		else if (dlg == m_ReplaceDialog)
		{
			txt = wxT("Replace");
			idMenu = ID_ReplaceDialog;
			m_ReplaceDialog = NULL;
		}
		else
		{
			txt = wxT("Unknown");
			idMenu = wxID_ANY;

			wxFAIL_MSG(wxT("unexpected event"));
		}

		if (idMenu != wxID_ANY)
		{
			GetMenuBar()->Check(idMenu, false);
		}

		dlg->Destroy();
	}
	else
	{
		wxLogError(wxT("Unknown find dialog event!"));
	}
}
Esempio n. 6
0
static void ProcFile( char * fname )
/**********************************/
{
    int         ftype;
    char *      name;
    int         status;
    int         namelen;
    char *      bak;

    namelen = strlen( fname ) + 5;
    name = alloca( namelen );
    if( name == NULL ) Suicide();           // null == no stack space left.
    strcpy( name, fname );
    ReplaceExt( name, ".obj", FALSE );
    InFile = QOpen( name, O_RDONLY | O_BINARY, 0 );
    for(;;) {
        CleanRecStuff();
        ftype = ReadRec();
        if( ftype == ENDLIBRARY || ftype == ENDFILE ) {
            break;
        } else if( ftype == LIBRARY ) {
            Warning( "exclude option does not apply to libraries" );
            FreeList( ExcludeList );
            ExcludeList = NULL;
        } else if( ftype != OBJECT ) {
            Error( "file is not a standard OBJECT or LIBRARY file" );
        }
        OutFile = QOpen( TEMP_OBJ_NAME, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0 );
        do {
            ProcessRec();
            status = ReadRec();
        } while( status == OK );
        if( status == ENDMODULE ) {
            ProcessRec();           // process the modend rec.
            DoReplace();
        } else {
            Error( "premature end of file encountered" );
        }
        FreeList( ExcludeList );    // do this here so concatenated .obj files
        ExcludeList = NULL;         // only have the first module excluded.
    }
    CloseFiles();
    if( MakeBackup ) {
        bak = alloca( namelen );
        if( bak == NULL ) Suicide();           // null == no stack space left.
        strcpy( bak, name );
        if( ftype == ENDLIBRARY ) {
            ReplaceExt( bak, ".bak", TRUE );
        } else {
            ReplaceExt( bak, ".bob", TRUE );
        }
        CopyFile( name, bak );
    }
    QRemove( name );
    if( ftype == ENDLIBRARY ) {
        rename( TEMP_LIB_NAME, name );
    } else {
        rename( TEMP_OBJ_NAME, name );
    }
    FileCleanup();
}
Esempio n. 7
0
/*>BOOL blRepOneSChain(PDB *pdb, char *ResSpec, char aa, char *ChiTable,
                     char *RefCoords)
   ---------------------------------------------------------------------
*//**

   \param[in,out] *pdb        PDB linked list to modify
   \param[in]     *ResSpec    Residue spec for residue to replace in the
                              format [c]nnn[i]
   \param[in]     aa          The 1-letter code for the new sidechain
   \param[in]     *ChiTable   The equivalent Chi table
   \param[in]     *RefCoords  The reference coordinates file
   \return                      Success?

   Replace a single sidechain. Takes a PDB linked list, a residues
   specfication (in the form [c]nnn[i] where [c] is an optional chain
   name, nnn is a residue number and [i] is an optional insert code)
   and a 1-letter code of the required sidechain and does a simple
   maximum overlap replacement of the sidechain. Also requires filenames 
   of the two datafiles.
   
-  12.08.96 Original based on RepSChain()
-  15.08.96 Removed unused variables
-  07.07.14 Use bl prefix for functions By: CTP
-  23.02.15 Modified for new blRenumAtomsPDB() which takes an offset
*/
BOOL blRepOneSChain(PDB *pdb, char *ResSpec, char aa, char *ChiTable,
                  char *RefCoords)
{
   PDB   *ResStart,                 /* Start of residue                 */
         *NextRes;                  /* Start of next residue            */
   BOOL  noenv = FALSE;             /* Flag for no env. var. found      */
   
   if(sFirstCall)
   {
      FILE  *fp_ChiTable;

      /* Allocate 2D array for equivalent torsions                      */
      if((sChiTab = (int **)blArray2D(sizeof(int), NUMAAKNOWN, NUMAAKNOWN)) 
         == NULL)
         return(FALSE);
   
      /* Open files                                                     */
      if((fp_ChiTable = blOpenFile(ChiTable,"DATADIR","r",&noenv)) == NULL)
      {
         if(noenv)
         {
            sprintf(gRSCError,"DATADIR environment variable not set\n");
         }
         else
         {
            sprintf(gRSCError,"Unable to open chi link table: %s\n",
                    ChiTable);
         }
         return(FALSE);
      }

      if((sFp_RefCoords = blOpenFile(RefCoords,"DATADIR","r",&noenv)) == 
         NULL)
      {
         if(noenv)
         {
            sprintf(gRSCError,"DATADIR environment variable not set\n");
         }
         else
         {
            sprintf(gRSCError,"Unable to open reference coordinates: \
%s\n", RefCoords);
         }
         return(FALSE);
      }

      /* Read the equivalent chi table and the atom table               */
      ReadChiTable(fp_ChiTable, sChiTab);
      
      /* Close the table files                                          */
      fclose(fp_ChiTable);
      
      sFirstCall = FALSE;
   }
   
   /* Find the specified residue and the one following                  */
   if((ResStart = blFindResidueSpec(pdb, ResSpec))==NULL)
   {
      sprintf(gRSCError,"Residue specification not in PDB list\n");
      return(FALSE);
   }
   NextRes = blFindNextResidue(ResStart);
   
   /* If there is a sequence mismatch, replace the residue              */
   if(aa != blThrone(ResStart->resnam))
   {
      if(DoReplace(ResStart, NextRes, aa, sChiTab, sFp_RefCoords) == 
         NULL) 
      {
         return(FALSE);
      }
   }
   
   blRenumAtomsPDB(pdb, 1);
   
   return(TRUE);
}
Esempio n. 8
0
/*>BOOL blRepSChain(PDB *pdb, char *sequence, char *ChiTable,
                  char *RefCoords)
   ----------------------------------------------------------
*//**

   \param[in,out] *pdb        PDB linked list to modify
   \param[in]     *sequence   The 1-letter code required for the structure
   \param[in]     *ChiTable   The equivalent Chi table
   \param[in]     *RefCoords  The reference coordinates file
   \return                      Success?

   Replace sidechains. Takes a PDB linked list and a 1-letter code 
   sequence and replaces the sidechains. Also requires filenames of the 
   two datafiles. DEL residues in the pdb linked list will be skipped 
   as will -'s in the sequence
   
-  12.05.92 Original
-  14.05.92 Corrected handling of matching DEL and -
-  21.06.93 Changed to allocate chitab using Array2D
-  14.03.94 Changed logic of return value. Now places error messages in
            gRSCError.
-  09.11.94 Uses OpenFile() to look in $(DATADIR) is the file wasn't
            found as specified.
-  12.08.96 Made static variables external to this routine as they are
            shared by RepOneSChain(). sChiTab was being allocated on every
            call instead of just the first one.
-  07.07.14 Use bl prefix for functions By: CTP
-  23.02.15 Modified for new blRenumAtomsPDB() which takes an offset

*/
BOOL blRepSChain(PDB  *pdb,         /* PDB linked list                  */
                 char *sequence,    /* Sequence 1-letter code           */
                 char *ChiTable,    /* Equivalent torsion table filename*/
                 char *RefCoords)   /* Reference coordinate filename    */
{
   int   resnum;                    /* Current residue number           */
   char  insert[8],                 /* Current insert code              */
         *seq;                      /* Pointer to aa in sequence        */
   PDB   *p,                        /* General PDB pointer              */
         *ResStart,                 /* Start of residue                 */
         *NextRes;                  /* Start of next residue            */
   BOOL   noenv = FALSE;            /* Flag for no env. var. found      */
   
   if(sFirstCall)
   {
      FILE  *fp_ChiTable;

      /* Allocate 2D array for equivalent torsions                      */
      if((sChiTab = (int **)blArray2D(sizeof(int), NUMAAKNOWN, NUMAAKNOWN)) 
         == NULL)
         return(FALSE);
   
      /* Open files                                                     */
      if((fp_ChiTable = blOpenFile(ChiTable,"DATADIR","r",&noenv)) == NULL)
      {
         if(noenv)
         {
            sprintf(gRSCError,"DATADIR environment variable not set\n");
         }
         else
         {
            sprintf(gRSCError,"Unable to open chi link table: %s\n",
                    ChiTable);
         }
         return(FALSE);
      }

      if((sFp_RefCoords = blOpenFile(RefCoords,"DATADIR","r",&noenv)) == 
         NULL)
      {
         if(noenv)
         {
            sprintf(gRSCError,"DATADIR environment variable not set\n");
         }
         else
         {
            sprintf(gRSCError,"Unable to open reference coordinates: \
%s\n", RefCoords);
         }
         return(FALSE);
      }

      /* Read the equivalent chi table and the atom table               */
      ReadChiTable(fp_ChiTable, sChiTab);
      
      /* Close the table files                                          */
      fclose(fp_ChiTable);
      
      sFirstCall = FALSE;
   }
   
   /* Step along the PDB linked list isolating a residue at a time and
      replacing it if necessary. The loop also steps along the sequence
      and will end if the sequence string ends.
   */
   for(p=pdb, seq = sequence; p && *seq != '\0'; NEXT(p))
   {
      ResStart = p;           /* Start of residue                       */
      resnum = p->resnum;
      strcpy(insert,p->insert);
      
      /* Move to end of residue and store pointer to next residue       */
      while(p->next && p->next->resnum == resnum 
                    && !strcmp(p->next->insert, insert))
         NEXT(p);
      NextRes = p->next;
      
      /* If its a DEL, step over any - in required sequence             */
      if(!strncmp(ResStart->resnam,"DEL",3))
      {
         while(*seq == '-') seq++;
      }
      else     /* Not a DEL, see if it needs replacing                  */
      {
         /* If there is a sequence mismatch, replace the residue        */
         if(*seq != blThrone(p->resnam))
            p = DoReplace(ResStart,NextRes,*seq,sChiTab,sFp_RefCoords);
         if(p == NULL) return(FALSE);

         /* Step to the next sequence item which isn't a -              */
         while(*(++seq) == '-') ;
      }
   }
   
   blRenumAtomsPDB(pdb, 1);
   
   return(TRUE);
}
Esempio n. 9
0
LRESULT FindReplDlg::OnReplaceAll(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	DoReplace(0);
	return 0;
}
void FindReplDlgFltk::OnReplaceSel()
{
	DoReplace(1);
}
void FindReplDlgFltk::OnReplaceAll()
{
	DoReplace(0);
}