Exemple #1
0
int
cd_glob(
    char *	glob,
    int		verbose)
{
    char *regex;
    char *regex_path;
    char *s;
    char *uqglob;
    int   result;

    char *tpath_on_disk = NULL;

    if (disk_name == NULL) {
	g_printf(_("Must select disk before changing directory\n"));
	return 0;
    }

    uqglob = unquote_string(glob);
    regex = glob_to_regex(uqglob);
    dbprintf(_("cd_glob (%s) -> %s\n"), uqglob, regex);
    if ((s = validate_regexp(regex)) != NULL) {
        g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob);
        puts(s);
	amfree(regex);
	amfree(uqglob);
        return 0;
    }
    /*
     * glob_to_regex() anchors the beginning of the pattern with ^,
     * but we will be tacking it onto the end of the current directory
     * in add_file, so strip that off.  Also, it anchors the end with
     * $, but we need to match a trailing /, add it if it is not there
     */
    regex_path = g_strdup(regex + 1);
    amfree(regex);
    if(regex_path[strlen(regex_path) - 2] != '/' ) {
	regex_path[strlen(regex_path) - 1] = '\0';
	strappend(regex_path, "/$");
    }

    /* convert path (assumed in cwd) to one on disk */
    if (g_str_equal(disk_path, "/"))
        tpath_on_disk = g_strconcat("/", regex_path, NULL);
    else {
        char *clean_disk_tpath = clean_regex(disk_tpath, 0);
        tpath_on_disk = g_strjoin(NULL, clean_disk_tpath, "/", regex_path, NULL);
        amfree(clean_disk_tpath);
    }

    result = cd_dir(tpath_on_disk, uqglob, verbose);

    amfree(regex_path);
    amfree(tpath_on_disk);
    amfree(uqglob);

    return result;
}
Exemple #2
0
int
cd_regex(
    char *	regex,
    int		verbose)
{
    char *s;
    char *uq_orig_regex;
    char *uqregex;
    int  len_uqregex;
    int  result;

    char *tpath_on_disk = NULL;

    if (disk_name == NULL) {
	g_printf(_("Must select disk before changing directory\n"));
	return 0;
    }

    uq_orig_regex = unquote_string(regex);
    uqregex = g_strdup(uq_orig_regex);

    /* Add a terminating '/' if it is not there, maybe before a '$' */
    len_uqregex = strlen(uqregex);
    if (uqregex[len_uqregex-1] == '$') {
	if (uqregex[len_uqregex-2] != '/') {
	    uqregex[len_uqregex-1] = '\0';
	    strappend(uqregex, "/$");
	}
    } else if (uqregex[len_uqregex-1] != '/') {
	//uqregex[len_uqregex-1] = '\0';
	strappend(uqregex, "/");
    }
    if ((s = validate_regexp(uqregex)) != NULL) {
	g_printf(_("\"%s\" is not a valid regular expression: "), uq_orig_regex);
	amfree(uqregex);
	amfree(uq_orig_regex);
	puts(s);
	return 0;
    }

    /* convert path (assumed in cwd) to one on disk */
    if (g_str_equal(disk_path, "/"))
        tpath_on_disk = g_strconcat("/", uqregex, NULL);
    else {
        char *clean_disk_tpath = clean_regex(disk_tpath, 0);
        tpath_on_disk = g_strjoin(NULL, clean_disk_tpath, "/", regex, NULL);
        amfree(clean_disk_tpath);
    }

    result = cd_dir(tpath_on_disk, uq_orig_regex, verbose);

    amfree(tpath_on_disk);
    amfree(uqregex);
    amfree(uq_orig_regex);

    return result;
}
Exemple #3
0
void
cd_regex(
    char *	regex,
    int		verbose)
{
    char *s;
    char *uq_orig_regex;
    char *uqregex;
    int  len_uqregex;

    char *path_on_disk = NULL;

    if (disk_name == NULL) {
	g_printf(_("Must select disk before changing directory\n"));
	return;
    }

    uq_orig_regex = unquote_string(regex);
    uqregex = stralloc(uq_orig_regex);

    /* Add a terminating '/' if it is not there, maybe before a '$' */
    len_uqregex = strlen(uqregex);
    if (uqregex[len_uqregex-1] == '$') {
	if (uqregex[len_uqregex-2] != '/') {
	    uqregex[len_uqregex-1] = '\0';
	    strappend(uqregex, "/$");
	}
    } else if (uqregex[len_uqregex-1] != '/') {
	//uqregex[len_uqregex-1] = '\0';
	strappend(uqregex, "/");
    }
    if ((s = validate_regexp(uqregex)) != NULL) {
	g_printf(_("\"%s\" is not a valid regular expression: "), uq_orig_regex);
	amfree(uqregex);
	amfree(uq_orig_regex);
	puts(s);
	return;
    }

    /* convert path (assumed in cwd) to one on disk */
    if (strcmp(disk_path, "/") == 0)
        path_on_disk = stralloc2("/", uqregex);
    else {
        char *clean_disk_path = clean_regex(disk_path);
        path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
        amfree(clean_disk_path);
    }

    cd_dir(path_on_disk, uq_orig_regex, verbose);

    amfree(path_on_disk);
    amfree(uqregex);
    amfree(uq_orig_regex);
}
Exemple #4
0
void
cd_regex(
    char *	regex)
{
    char *s;
    char *uqregex;

    char *path_on_disk = NULL;

    if (disk_name == NULL) {
	g_printf(_("Must select disk before changing directory\n"));
	return;
    }

    uqregex = unquote_string(regex);
    if ((s = validate_regexp(uqregex)) != NULL) {
	g_printf(_("\"%s\" is not a valid regular expression: "), uqregex);
	amfree(uqregex);
	puts(s);
	return;
    }

    /* convert path (assumed in cwd) to one on disk */
    if (g_str_equal(disk_path, "/"))
        path_on_disk = g_strconcat("/", regex, NULL);
    else {
        char *clean_disk_path = clean_regex(disk_path, 0);
        path_on_disk = g_strjoin(NULL, clean_disk_path, "/", regex, NULL);
        amfree(clean_disk_path);
    }

    cd_dir(path_on_disk, uqregex);

    amfree(path_on_disk);
    amfree(uqregex);
}
Exemple #5
0
int		main(int ac, char **av, char **env)
{
  char	**tab;
  char	**path;
  char	*cmd;
  
  welcome();
  while (42)
    {
      prompt();
      tab = get_command();
      if (tab[0][0] == 'c' && tab[0][1] == 'd')
	cd_dir(tab[1]);
      else
	{
	  path = my_getenv(env);
	  cmd = find_path(path,tab[0]);
	  tab[0] = cmd;
	  exec_cmd(cmd, tab ,env);
	  wait(NULL);
	}
    }
  return (0);
}
void FileList::change_dir(const QString &cd_dir_str)
{
  QDir cd_dir(cd_dir_str);

  if (!cd_dir.exists())
    return;
  

  // in mac osX, I need this fileter to show all files
  cd_dir.setFilter(QDir::AllEntries | QDir::AllDirs| QDir::System | QDir::Hidden);
  //cd_dir.setFilter(QDir::AllDirs| QDir::System | QDir::Hidden);
  QFileInfoList file_info_list = cd_dir.entryInfoList();

  // reset cur_dir_
  if (cur_dir_=="") /* win , remove c:\'s \ */
  {
    cur_dir_ = cd_dir_str.left(cd_dir_str.length()-1);
  }
  else
  {
    cur_dir_ = cd_dir_str;
  }

  change_dir(file_info_list);
  //change_title_to_cur_path();

#if 0
  clear();

  qDebug("cur_dir_ : %s ## cur_dir_ len: %d", cur_dir_.toAscii().data(), cur_dir_.length() );
  for (int i = 0; i < file_info_list.size(); ++i) 
  {
    //if ( file_info_list.at(i).fileName() =="." ||  file_info_list.at(i).fileName()=="..")
    if ( file_info_list.at(i).fileName() ==".")
    {
      continue;
    }
    FileListWidgetItem *fi = new FileListWidgetItem (this);
#if 0
    if ( file_info_list.at(i).fileName() =="..")
    {
      fi->setText(0, file_info_list.at(i).absoluteFilePath() + "%");
      fi->set_real_str(file_info_list.at(i).absoluteFilePath() );
    }
    else
#endif
    {
      // if isDir put first, /etc will determine to dir
      if ( file_info_list.at(i).isSymLink())
      //if ( file_info_list.at(i).isDir())
      {
        fi->setText(0, file_info_list.at(i).fileName() + "@");
        //fi->setText(0, file_info_list.at(i).absoluteFilePath() + "/");
        //fi->setText(0, file_info_list.at(i).fileName());
      }
      else if ( file_info_list.at(i).isDir())
      //else if ( file_info_list.at(i).isSymLink())
      {
        fi->setText(0, file_info_list.at(i).fileName() + "/");
        //fi->setText(0, file_info_list.at(i).absoluteFilePath() + "/");
        //fi->setText(0, file_info_list.at(i).fileName());
      }
      else
      {
        fi->setText(0, file_info_list.at(i).fileName() );
      }
      fi->set_real_str(file_info_list.at(i).fileName() );
      //fi->set_real_str(file_info_list.at(i).absoluteFilePath() );
    }	
 
  }

  if (cur_dir_=="") /* win , remove c:\'s \ */
  {
    cur_dir_ = cd_dir_str.left(cd_dir_str.length()-1);
  }
  else
  {
    cur_dir_ = cd_dir_str;
  }
  change_title_to_cur_path();
#endif
}
Exemple #7
0
int cmd_cdd(char *param)
{
	return cd_dir(param, 1, "CDD");
}
Exemple #8
0
int cmd_chdir(char *param)
{
	return cd_dir(param, 0, "CHDIR");
}