MCPcopy Create free account
hub / github.com/Genivia/ugrep / deselect

Method deselect

src/query.cpp:2920–3036  ·  view source on GitHub ↗

chdir back up one level

Source from the content-addressed store, hash-verified

2918
2919// chdir back up one level
2920void Query::deselect()
2921{
2922 if (selected_file_.empty())
2923 {
2924 if (flag_stdin)
2925 {
2926 message("cannot chdir .. because standard input is searched");
2927 return;
2928 }
2929
2930 if (!Static::arg_files.empty())
2931 {
2932 message("cannot chdir .. because file or directory arguments are present");
2933 return;
2934 }
2935
2936#ifdef OS_WIN
2937 if (dirs_.size() == 3 && dirs_.at(1) == ':' && dirs_.at(2) == PATHSEPCHR)
2938 return;
2939#else
2940 if (dirs_ == PATHSEPSTR)
2941 return;
2942#endif
2943
2944 if (dirs_.empty())
2945 {
2946 char *cwd = getcwd0();
2947 if (cwd != NULL)
2948 {
2949 size_t n = strlen(cwd);
2950 dirs_.assign(cwd);
2951 wdir_.assign(cwd);
2952 if (n == 0 || cwd[n-1] != PATHSEPCHR)
2953 dirs_.append(PATHSEPSTR);
2954 free(cwd);
2955 }
2956 }
2957
2958 if (dirs_.empty())
2959 {
2960 if (chdir("..") < 0)
2961 return;
2962
2963 dirs_.assign(".." PATHSEPSTR);
2964 }
2965 else
2966 {
2967 dirs_.pop_back();
2968
2969 size_t n = dirs_.find_last_of(PATHSEPCHR);
2970
2971 if (n != std::string::npos && dirs_.front() == PATHSEPCHR)
2972 {
2973 if (chdir(dirs_.substr(0, n + 1).c_str()) < 0)
2974 return;
2975
2976 dirs_.resize(n + 1);
2977 }

Callers

nothing calls this directly

Calls 11

getcwd0Function · 0.85
chdirFunction · 0.85
set_terminal_hyperlinkFunction · 0.85
atMethod · 0.80
assignMethod · 0.80
swapMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45
resetMethod · 0.45
restoreMethod · 0.45

Tested by

no test coverage detected