Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <curl/curl.h>
- #include <regex.h>
- #include <fstream>
- using namespace std;
- int getFileSize(const string &fileName){
- ifstream file(fileName.c_str(), ifstream::in | ifstream::binary);
- if(!file.is_open()){
- return -1;
- }
- file.seekg(0,ios::end);
- int fileSize = file.tellg();
- file.close();
- return fileSize;
- }
- size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *plik){
- size_t written = fwrite(ptr,size,nmemb,plik);
- return written;
- }
- int main(int argos, char* argv[2]){
- CURL *curl;
- curl = curl_easy_init();
- CURLcode res;
- FILE *plikk;
- plikk = fopen("text.txt","a+");
- int lngh = getFileSize("text.txt");
- if(lngh==0){
- if(curl){
- curl_easy_setopt(curl,CURLOPT_URL,argv[1]);//pobiera url
- curl_easy_setopt(curl, CURLOPT_POST, 1);//
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
- "title=CURL&action=edit");
- curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,write_data);
- curl_easy_setopt(curl,CURLOPT_WRITEDATA,plikk);
- res = curl_easy_perform(curl);
- if(res != CURLE_OK){
- cout<<"curl_easy_perform() failed \n";
- //fprintf(stderr,"curl_easy_perform() failed: %s",curl_easy_strerror(res));
- return 1;
- }
- curl_easy_cleanup(curl);
- fclose(plikk);
- }
- FILE *file;
- file = fopen("text.txt","r");
- int status;
- regmatch_t pm[2];
- char msgbuf[100];
- regex_t myRegex;
- char *buffer;
- size_t result;
- long lsize;
- if(file){
- fseek(file,0,SEEK_END);
- lsize = ftell(file);
- rewind(file);
- buffer= (char*)malloc (sizeof(char)*lsize);
- if (buffer == NULL){
- cout<<"BUFFER MA WARTOSC NULL \n";
- return(1);
- }
- result =fread(buffer,1,lsize,file);
- if(result !=lsize){
- cout<<"BLAD ODCZYTU";
- return(1);
- }
- status= regcomp(&myRegex,argv[2],REG_EXTENDED | REG_ICASE);
- if(status){
- cout<<"nie mozna skompilowac regex\n";
- exit(1);
- }
- status = regexec(&myRegex,buffer,1,pm,REG_EXTENDED|REG_ICASE);
- cout<< "STATUS"<<endl;
- if( !status ){
- puts("Match");
- }
- else if( status == REG_NOMATCH ){
- puts("No match");
- }
- else{
- regerror(status, &myRegex, msgbuf, sizeof(msgbuf));
- fprintf(stderr, "Regex match failed: %s\n", msgbuf);
- exit(1);
- }
- fclose(file);
- }
- }
- else cout <<"nie otworzylismy pliku" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment