Example #1
0
void permute(unsigned int **result, char *a, int l, int r, int *len) {
  static int buflen = 10;
  int *new_result;
  int i, aint;
  if(l == 0) {
    *len = 0;
    (*result)[(*len)++] = atoi(a);
  }
  if(l == r) {
    if(a[0] == '0') return;
    aint = atoi(a);
    if(!icontains(*result, *len, aint)) {
      if(*len >= buflen) {
        buflen = (int)(((float)*len)*1.5f);
        new_result = realloc(*result, buflen * sizeof(*result));
        if(new_result != NULL) {
          *result = new_result;
        }
      }
      fprintf(stdout, "%d,", aint);
      (*result)[(*len)++] = aint;
    }
  }else {
    for(i=l;i<=r;i++) {
      swap((a+l), (a+i));
      permute(result, a, l+1, r, len);
      swap((a+l), (a+i)); //backtrack
    }
  }
}
 bool expectStringContent(std::shared_ptr<RNetworkResponse> response, std::string& content, RFutureError& error) {
     if (response->content_type.empty()) {
         content.clear();
         return true;
     } else if (icontains(response->content_type, ContentType::json()) ||
                icontains(response->content_type, ContentType::multipart_mixed()) ||
                icontains(response->content_type, ContentType::text()) ||
                icontains(response->content_type, ContentType::xml()) ||
                icontains(response->content_type, ContentType::x_www_form_urlencoded())) {
         content = decodeString(response);
         return true;
     } else {
         makeParsingError(error, "unexpected content type: " + response->content_type);
         return false;
     }
 }
 bool expectJsonResponse(std::shared_ptr<RNetworkResponse> response, json11::Json& value, RFutureError& error) {
     if (icontains(response->content_type, ContentType::json())) {
         string content = decodeString(response);
         string e;
         value = json11::Json::parse(content, e);
         if (e.empty())
             return true;
         else {
             makeParsingError(error, e);
             return false;
         }
     } else {
         makeParsingError(error, "expecting application/json, current is " + response->content_type);
         return false;
     }
 }
 bool expectJsons(const std::vector<HttpContent>& contents, std::vector<json11::Json>& jsons, RFutureError& error) {
     
     for (auto& c : contents) {
         if (false == icontains(c.type, ContentType::json())) {
             makeParsingError(error, "expecting application/json, current is " + c.type + "; content = " + c.content);
             return false;
         }
         string e;
         json11::Json json = json11::Json::parse(c.content, e);
         if (false == e.empty()) {
             makeParsingError(error, "json parsing error: " + e);
             return false;
         }
         jsons.push_back(json);
     }
     return true;
 }
 bool expectMultiMixed(std::shared_ptr<RNetworkResponse> response, std::vector<HttpContent>& contents, RFutureError& error) {
     string contentType = response->content_type;
     
     if (false == icontains(contentType, ContentType::multipart_mixed())) {
         makeParsingError(error, "expecting multipart/mixed, current is " + response->content_type);
         return false;
     }
     string text = decodeString(response);
     contents.clear();
     auto boundaryStart = ifind_after(contentType.begin(), contentType.end(), "boundary=");
     string boundary;
     if (contentType.end() == boundaryStart) {
         if (istartsWith(text, "--Boundary")) {
             string lineFeed = "\r\n";
             auto boundaryEnd = search(text.begin(), text.end(), lineFeed.begin(), lineFeed.end());
             if (text.end() != boundaryEnd) {
                 boundary = string(text.begin(), boundaryEnd);
             }
         }
         if (boundary.empty()) {
             makeParsingError(error, "no boundary found");
             return false;
         }
     } else
         boundary = "--" + string(boundaryStart, contentType.end());
     auto position = find_after(text.begin(), text.end(), boundary);
     while (text.end() != position) {
         auto typeBegin = ifind_after(position, text.end(), "Content-Type: ");
         auto contentBegin = find_after(typeBegin, text.end(), "\r\n");
         auto contentEnd = search(contentBegin, text.end(), boundary.begin(), boundary.end());
         if (text.end() != contentEnd) {
             auto typeEnd = contentBegin - 2;
             HttpContent c;
             c.type = string(typeBegin, typeEnd);
             c.content = string(contentBegin, contentEnd);
             contents.push_back(c);
         }
         position = find_after(contentEnd, text.end(), boundary);
     }
     if (0 == contents.size()) {
         makeParsingError(error, "not multipart/mixed format:\r\n" + text);
         return false;
     } else
         return true;
 }
Example #6
0
    void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
    {
        static const std::string example = Strings::format(
            "The argument should be a substring to search for, or no argument to display all libraries.\n%s",
            Commands::Help::create_example_string("search png"));
        args.check_max_arg_count(1, example);
        const std::unordered_set<std::string> options =
            args.check_and_get_optional_command_arguments({OPTION_GRAPH, OPTION_FULLDESC});

        auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports);

        if (!sources_and_errors.errors.empty())
        {
            if (vcpkg::g_debugging)
            {
                print_error_message(sources_and_errors.errors);
            }
            else
            {
                for (auto&& error : sources_and_errors.errors)
                {
                    System::println(
                        System::Color::warning, "Warning: an error occurred while parsing '%s'", error->name);
                }
                System::println(System::Color::warning,
                                "Use '--debug' to get more information about the parse failures.\n");
            }
        }

        auto& source_paragraphs = sources_and_errors.paragraphs;
        if (options.find(OPTION_GRAPH) != options.cend())
        {
            const std::string graph_as_string = create_graph_as_string(source_paragraphs);
            System::println(graph_as_string);
            Checks::exit_success(VCPKG_LINE_INFO);
        }

        if (args.command_arguments.empty())
        {
            for (const auto& source_control_file : source_paragraphs)
            {
                do_print(*source_control_file->core_paragraph, options.find(OPTION_FULLDESC) != options.cend());
                for (auto&& feature_paragraph : source_control_file->feature_paragraphs)
                {
                    do_print(source_control_file->core_paragraph->name,
                             *feature_paragraph,
                             options.find(OPTION_FULLDESC) != options.cend());
                }
            }
        }
        else
        {
            const auto& icontains = Strings::case_insensitive_ascii_contains;

            // At this point there is 1 argument
            auto&& args_zero = args.command_arguments[0];
            for (const auto& source_control_file : source_paragraphs)
            {
                auto&& sp = *source_control_file->core_paragraph;

                bool contains_name = icontains(sp.name, args_zero);
                if (contains_name || icontains(sp.description, args_zero))
                {
                    do_print(sp, options.find(OPTION_FULLDESC) != options.cend());
                }

                for (auto&& feature_paragraph : source_control_file->feature_paragraphs)
                {
                    if (contains_name || icontains(feature_paragraph->name, args_zero) ||
                        icontains(feature_paragraph->description, args_zero))
                    {
                        do_print(sp.name, *feature_paragraph, options.find(OPTION_FULLDESC) != options.cend());
                    }
                }
            }
        }

        System::println(
            "\nIf your library is not listed, please open an issue at and/or consider making a pull request:\n"
            "    https://github.com/Microsoft/vcpkg/issues");

        Checks::exit_success(VCPKG_LINE_INFO);
    }