Example #1
0
PRIVATE int cmd_auto(struct comal_line *line)
{
	char buf[MAX_LINELEN];
	char *buf2;
	int result = 0;
	int direct_cmd = 0;
	long nr = line->lc.twonum.num1;
	long step = line->lc.twonum.num2;
	struct comal_line *work;
	struct comal_line *aline;

	while (!direct_cmd) {
		if (nr < 0)
			return 0;	/* nr<0 after nr+=step past MAXINT */

		work = search_line(nr, 1);

		if (work) {
			buf2 = buf;
			line_list(&buf2, work);
		} else
			sprintf(buf, "%9ld  ", nr);

		if (sys_edit(MSG_DIALOG, buf, MAX_LINELEN, 11))
			return 0;

		aline = crunch_line(buf);

		direct_cmd = !aline->ld;
		result = process_comal_line(aline);
		nr += step;
	}

	return result;
}
Example #2
0
PRIVATE int cmd_edit(struct comal_line *line)
{
	char buf[MAX_LINELEN];
	char *buf2;
	int result = 0;
	long nr = line->lc.twonum.num1;
	long to = line->lc.twonum.num2;
	struct comal_line *work;
	struct comal_line *aline;

	while (result == 0) {
		if (nr > to || nr < 0)
			return 0;	/* nr<0 after nr++ at MAXINT */

		work = search_line(nr, 0);

		if (!work)
			return 0;

		nr = work->ld->lineno + 1;

		buf2 = buf;
		line_list(&buf2, work);

		if (sys_edit(MSG_DIALOG, buf, MAX_LINELEN, 10))
			return 0;

		aline = crunch_line(buf);
		result = process_comal_line(aline);
	}

	return result;
}
Example #3
0
int main()
{
	try {
		cout << "Enter file name: ";
		string filename;
		cin >> filename;
		ifstream is(filename.c_str());
		if (!is) error("Error opening file.");

		cout << "Enter search term: ";
		string search_term;
		cin >> search_term;

		string line;
		int line_num = 0;
		while (getline(is,line)) {
			line_num++;
			if (search_line(line,search_term))
				cout << line_num << ". " << line << endl;
		}
	}
	catch(runtime_error e) {
		cerr << e.what() << endl;
	}
	return 0;
}
Example #4
0
char	*get_path_cmd(char **env, char *cmd)
{
	char	**path;
	char	*tmp;
	int		i;

	i = 0;
	if ((tmp = search_line(&env, "PATH=")) != NULL)
	{
		tmp = ft_strsub(tmp, 5, ft_strlen(tmp) - 5);
		path = ft_strsplit(tmp, ':');
		if (access(cmd, F_OK) == 0)
			return (cmd);
		while (path[i])
		{
			path[i] = ft_strjoin(path[i], "/");
			path[i] = ft_strjoin(path[i], cmd);
			if (access(path[i], F_OK) == 0)
				return (path[i]);
			i++;
		}
		free(tmp);
	}
	return (NULL);
}
Example #5
0
static void		cd_minus(char ***env, char *tmp)
{
	if ((tmp = search_line(env, "OLDPWD=")) != NULL)
	{
		tmp = ft_strsub(tmp, 7, ft_strlen(tmp) - 7);
		chdir(tmp);
		ft_update_env(env);
		tmp = NULL;
		ft_putendl(getcwd(tmp, 0));
	}
}
		bool binarySearch(int low, int high, int &size, int& target,vector<vector<int> > &matrix)
		{
			if(low==high)
				return search_line(matrix,target,low,size);
			int mid=(low+high)/2;

			if(target>matrix[mid][size-1])
				return binarySearch(mid+1,high,size,target,matrix);
			else
				return binarySearch(low,mid,size,target,matrix);

		}
Example #7
0
static void		cd_home(char ***env, char *tmp)
{
	int		i;

	i = 0;
	if ((tmp = search_line(env, "HOME=")) != NULL)
	{
		tmp = ft_strsub(tmp, 5, ft_strlen(tmp) - 5);
		chdir(tmp);
		ft_update_env(env);
	}
}
Example #8
0
static int		ft_update_env(char ***env)
{
	int		num;
	char	*tmp;
	char	*pwd;

	pwd = NULL;
	pwd = getcwd(pwd, 0);
	tmp = "";
	if ((num = search_num_line(env, "OLDPWD=")) != -1)
		(*env)[num] = ft_strjoin("OLD", search_line(env, "PWD="));
	if ((num = search_num_line(env, "PWD=")) != -1)
	{
		(*env)[num] = ft_strjoin(tmp, "PWD=");
		(*env)[num] = ft_strjoin((*env)[num], pwd);
	}
	free(pwd);
	return (1);
}
Example #9
0
bool wxExTextFile::MatchLine(wxString& line)
{
  bool match = false;
  int count = 1;

  wxExFindReplaceData* frd = wxExFindReplaceData::Get();

  if (!frd->UseRegularExpression() || !frd->GetRegularExpression().IsValid())
  {
    if (m_Tool.GetId() == ID_TOOL_REPORT_FIND)
    {
      std::string search_line(line);

      if (!frd->MatchCase())
      {
        std::transform(
          search_line.begin(), 
          search_line.end(), 
          search_line.begin(), 
          toupper);
      }

      const size_t start = search_line.find(m_FindString);

      if (start != wxString::npos)
      {
        if (frd->MatchWord())
        {
          if (( start == 0 ||
               (start > 0 && !IsWordCharacter(search_line[start - 1]))) &&
              !IsWordCharacter(search_line[start + m_FindString.length()]))
          {
            match = true;
          }
        }
        else
        {
          match = true;
        }
      }
    }
    else
    {
      count = line.Replace(
        frd->GetFindString(), 
        frd->GetReplaceString());

      if (count > 0)
      {
        m_Modified = true;
        match = true;
      }
    }
  }
  else
  {
    match = frd->GetRegularExpression().Matches(line);

    if (match && m_Tool.GetId() == ID_TOOL_REPORT_REPLACE)
    {
      count = frd->GetRegularExpression().ReplaceAll(
        &line, 
        frd->GetReplaceString());

      m_Modified = true;
    }
  }

  if (match)
  {
    IncActionsCompleted(count);
  }

  return match;
}