code: добавление функций writedata и download

master
MakhnovGA 2 лет назад
Родитель 13537a11c0
Сommit 6e1d4011cf

@ -13,7 +13,12 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="curl/include" />
</Compiler>
<Linker>
<Add library="libcurl.dll.a" />
<Add directory="curl/lib" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin/Release/lab_01" prefix_auto="1" extension_auto="1" />

@ -2,44 +2,44 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="824" topLine="19" />
<Cursor1 position="73" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="207" topLine="0" />
<Cursor1 position="211" topLine="0" />
</Cursor>
</File>
<File name="svg.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="123" topLine="0" />
<Cursor1 position="106" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="211" topLine="0" />
<Cursor1 position="980" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="73" topLine="0" />
<Cursor1 position="1502" topLine="23" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1618" topLine="44" />
<Cursor1 position="173" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="32" />
<Cursor1 position="167" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="173" topLine="0" />
<Cursor1 position="811" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -7,6 +7,8 @@
#include "svg.h"
#include "histogram_internal.h"
#include <curl/curl.h>
#include <sstream>
#include <string>
using namespace std;
@ -35,10 +37,28 @@ input_data(istream &tin, bool prompt){
return in;
}
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
res = curl_easy_perform(curl);
if(res != CURLE_OK){
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
exit(1);
}
curl_easy_cleanup(curl);
}
size_t data_size = item_size * item_count;
return 0;
}
int main(int argc, char* argv[]) {
if (argc > 1){
CURL* curl = curl_easy_init();
Input
download(const string& address) {
stringstream buffer;
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
@ -48,13 +68,21 @@ int main(int argc, char* argv[]) {
curl_easy_strerror(res));
exit(1);
}
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_cleanup(curl);
}
return 0;
return input_data(buffer, false);
}
int
main(int argc, char* argv[]) {
Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(cin, true);
}
curl_global_init(CURL_GLOBAL_ALL);
Input in = input_data(cin, false);
auto bins = make_histogramm(in.numbers, in.bin_count);
const auto bins = make_histogramm(input.numbers, input.bin_count);
show_histogram_svg(bins);
return 0;
}

@ -2,9 +2,14 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="395" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="97" topLine="0" />
<Cursor1 position="171" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -17,9 +22,4 @@
<Cursor1 position="168296" topLine="3336" />
</Cursor>
</File>
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="650" topLine="3" />
</Cursor>
</File>
</CodeBlocks_layout_file>

Загрузка…
Отмена
Сохранить