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; }
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; }
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); }
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); }