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

Function help

src/ugrep.cpp:14869–15240  ·  view source on GitHub ↗

print a helpful information for WHAT, if specified, and exit

Source from the content-addressed store, hash-verified

14867
14868// print a helpful information for WHAT, if specified, and exit
14869void help(const char *what)
14870{
14871 // strip = from =WHAT
14872 if (what != NULL && *what == '=')
14873 ++what;
14874
14875 // strip --no from --no-WHAT
14876 if (what != NULL && strncmp(what, "--no", 4) == 0)
14877 what += 4;
14878
14879 // strip one dash from --WHAT
14880 if (what != NULL && strncmp(what, "--", 2) == 0)
14881 ++what;
14882
14883 if (what == NULL || *what == '\0')
14884 {
14885 help(std::cout);
14886
14887 std::cout << "\n Specify `ugrep --help WHAT' for help on WHAT.\n\n";
14888 }
14889 else
14890 {
14891 std::stringstream text;
14892 help(text);
14893 const std::string& str = text.str();
14894
14895 int found = 0;
14896
14897 for (int pass = 0; pass < 2; ++pass)
14898 {
14899 size_t pos = 0;
14900
14901 while (true)
14902 {
14903 size_t end = str.find("\n -", pos + 1);
14904
14905 if (end == std::string::npos)
14906 end = str.find("\n\n", pos + 1);
14907
14908 if (end == std::string::npos)
14909 break;
14910
14911 size_t nl = str.find('\n', pos + 1);
14912
14913 // roughly find a case-independent match of WHAT
14914 for (size_t i = pos + 5; i < (pass == 0 ? nl : end); ++i)
14915 {
14916 size_t j = 0;
14917
14918 for (j = 0; what[j] != '\0'; ++j)
14919 if (((what[j] ^ str.at(i + j)) & ~0x20) != 0)
14920 break;
14921
14922 if (what[j] == '\0' || what[j] == '=' || isspace(static_cast<unsigned char>(what[j])))
14923 {
14924 if (pass == 0 ? i < nl: i > nl)
14925 {
14926 if (found == 0 && pass == 0)

Callers 2

query_uiMethod · 0.70
optionsFunction · 0.70

Calls 3

atMethod · 0.80
strMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected