mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Majority of the edits done using the following ruby script:
def update_loops(src)
dst, cnt = '', 0
block_indent, variable = nil, nil
src.each_line do |line|
if block_indent
if line =~ /^#{block_indent}([{}\t])|^\t*$/
block_indent = nil if $1 == '}'
line = line.gsub(%r{ ([^a-z>]) \(\*#{variable}\) | \*#{variable}\b | \b#{variable}(->) }x) do
$1.to_s + variable + ($2 == "->" ? "." : "")
end
else
block_indent = nil
end
elsif line =~ /^(\t*)c?iterate\((\w+), (?!diacritics::make_range)(.*\))$/
block_indent, variable = $1, $2
line = "#$1for(auto const& #$2 : #$3\n"
cnt += 1
end
dst << line
end
return dst, cnt
end
paths.each do |path|
src = IO.read(path)
cnt = 1
while cnt != 0
src, cnt = update_loops(src)
STDERR << "#{path}: #{cnt}\n"
end
File.open(path, "w") { |io| io << src }
end
89 lines
2.9 KiB
C++
89 lines
2.9 KiB
C++
#include "post.h"
|
|
#include "proxy.h"
|
|
#include "user_agent.h"
|
|
#include <text/case.h>
|
|
#include <text/encode.h>
|
|
#include <oak/oak.h>
|
|
|
|
static size_t receive_data (void* ptr, size_t size, size_t nmemb, void* udata)
|
|
{
|
|
std::map<std::string, std::string>* map = (std::map<std::string, std::string>*)udata;
|
|
|
|
std::string line((char*)ptr, ((char*)ptr) + nmemb * size);
|
|
while(line.size() > 1 && line.rfind("\r\n") == line.size()-2)
|
|
line.resize(line.size()-2);
|
|
|
|
auto sep = line.find(':');
|
|
if(sep != std::string::npos)
|
|
map->emplace(std::make_pair(text::lowercase(line.substr(0, sep)), line.substr(line.find_first_not_of(" \t", sep+1))));
|
|
|
|
return size * nmemb;
|
|
}
|
|
|
|
long post_to_server (std::string const& url, std::map<std::string, std::string> const& payload, std::map<std::string, std::string>* headersOut)
|
|
{
|
|
struct curl_httppost* formpost = NULL;
|
|
struct curl_httppost* lastptr = NULL;
|
|
|
|
for(auto const& pair : payload)
|
|
{
|
|
if(pair.second.find('@') == 0)
|
|
{
|
|
curl_formadd(&formpost, &lastptr,
|
|
CURLFORM_PTRNAME, pair.first.data(),
|
|
CURLFORM_NAMELENGTH, pair.first.size(),
|
|
CURLFORM_FILE, pair.second.substr(1).c_str(),
|
|
CURLFORM_END);
|
|
}
|
|
else if(pair.second != NULL_STR)
|
|
{
|
|
curl_formadd(&formpost, &lastptr,
|
|
CURLFORM_PTRNAME, pair.first.data(),
|
|
CURLFORM_NAMELENGTH, pair.first.size(),
|
|
CURLFORM_PTRCONTENTS, pair.second.data(),
|
|
CURLFORM_CONTENTSLENGTH, pair.second.size(),
|
|
CURLFORM_END);
|
|
}
|
|
}
|
|
|
|
long serverReply = 0;
|
|
if(CURL* handle = curl_easy_init())
|
|
{
|
|
std::string const userAgent = create_agent_info_string();
|
|
char errorbuf[CURL_ERROR_SIZE];
|
|
|
|
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
|
|
curl_easy_setopt(handle, CURLOPT_HTTPPOST, formpost);
|
|
curl_easy_setopt(handle, CURLOPT_USERAGENT, userAgent.c_str());
|
|
|
|
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errorbuf);
|
|
curl_easy_setopt(handle, CURLOPT_FAILONERROR, true);
|
|
curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1);
|
|
|
|
if(headersOut)
|
|
{
|
|
curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, &receive_data);
|
|
curl_easy_setopt(handle, CURLOPT_HEADERDATA, headersOut);
|
|
}
|
|
|
|
if(proxy_settings_t const& proxySettings = get_proxy_settings(url))
|
|
{
|
|
curl_easy_setopt(handle, CURLOPT_PROXY, proxySettings.server.c_str());
|
|
curl_easy_setopt(handle, CURLOPT_PROXYPORT, proxySettings.port);
|
|
curl_easy_setopt(handle, CURLOPT_PROXYTYPE, proxySettings.socks ? CURLPROXY_SOCKS4 : CURLPROXY_HTTP);
|
|
if(proxySettings.password != NULL_STR)
|
|
curl_easy_setopt(handle, CURLOPT_PROXYUSERPWD, (proxySettings.user + ":" + proxySettings.password).c_str());
|
|
}
|
|
|
|
CURLcode rc = curl_easy_perform(handle);
|
|
if(rc == 0)
|
|
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &serverReply);
|
|
else fprintf(stderr, "curl error (%d): %s\n", rc, errorbuf);
|
|
|
|
curl_easy_cleanup(handle);
|
|
}
|
|
|
|
curl_formfree(formpost);
|
|
return serverReply;
|
|
}
|