From 3841a366fa5911f7a81059138edaf2e7078f6211 Mon Sep 17 00:00:00 2001 From: tobast Date: Mon, 21 Nov 2011 21:46:03 +0100 Subject: [PATCH] Main done, displays like version, etc. done, ready to begin real coding! --- CurlPost.cpp | 5 ++++ CurlPost.h | 1 + Makefile | 26 ++++++++++++++++++ data.h | 13 +++++++++ func.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++---- func.h | 12 ++++++++- main.cpp | 31 +++++++++++++++++++++- 7 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 Makefile diff --git a/CurlPost.cpp b/CurlPost.cpp index b6e92d1..b5a34a9 100644 --- a/CurlPost.cpp +++ b/CurlPost.cpp @@ -90,6 +90,11 @@ void CurlPost::init() curl_global_init(CURL_GLOBAL_ALL); } +void CurlPost::clean() +{ + curl_global_cleanup(); +} + size_t postRequest_callbackReadout(char* ptr, size_t size, size_t nmemb, void* i_userdata) { // Here, we'll assume that ptr is a char string diff --git a/CurlPost.h b/CurlPost.h index 4ce0bad..ad82aec 100644 --- a/CurlPost.h +++ b/CurlPost.h @@ -56,6 +56,7 @@ class CurlPost { std::string execute(); static void init(); + static void clean(); protected: std::string url; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7e7cba5 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +# Makefile for pastebincl (command-line pastebin) by BASTIAN Théophile (aka Tobast) + +CXX=g++ +CXXFLAGS=-Wall -Werror -O2 +CXXLIBS=-lparameterread +TARGET=pastebincl +OBJS=CurlPost.o func.o main.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CXX) $(CXXLIBS) $^ $(CXXFLAGS) -o $@ + +%.o: %.cpp + $(CXX) $(CXXLIBS) -c $< $(CXXFLAGS) -o $@ + + + +.PHONY: clean + +clean: + rm -f *.o + +mrproper: clean + rm -f $(TARGET) + diff --git a/data.h b/data.h index 6c68863..265d239 100644 --- a/data.h +++ b/data.h @@ -36,6 +36,10 @@ #include "data_devcode.h" // TODO before compile, check this file +// TODO REDEFINE YOUR OS HERE! +#define UNIX +// #define WINDOWS + #define DEFAULT_PRIVATE "0" #define DEFAULT_NAME "" #define DEFAULT_EXPIRE "N" @@ -43,5 +47,14 @@ #define DEFAULT_USERKEY "" #define DEFAULT_OPTION "paste" + +enum FlagParameter { + P_NAME=1, P_SYNTAX=2, P_PRIVATE=4, P_EXPIRE=8, P_GUEST=16, P_HELP=32, P_VERSION=64, P_LICENCE=128 +}; + +#define SOFT_VERSION "0.1 INDEV" + +#define MANPAGE_SHORT "TODO write it." // TODO + #endif//DEF_DATA diff --git a/func.cpp b/func.cpp index c1e7563..6937629 100644 --- a/func.cpp +++ b/func.cpp @@ -29,11 +29,11 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/gpl.txt. -*/ + */ #include "func.h" -void initParameterRead(ParameterRead& pr) +bool initParameterRead(ParameterRead& pr, unsigned& flags) { pr.addValueParam("n"); pr.addValueParam("name"); @@ -44,13 +44,78 @@ void initParameterRead(ParameterRead& pr) pr.execute(); - if(!checkParameterRead(pr)) + if(!checkParameterRead(pr, flags)) return false; return true; } -bool checkParameterRead(ParameterRead& pr) +bool checkParameterRead(ParameterRead& pr, unsigned& flags) { - if( + try { + if(pr.isSet("licence")) + { + flags=P_LICENCE; + return true; + } + if(pr.isSet("h") || pr.isSet("?") || pr.isSet("help")) + { + flags=P_HELP; + return true; + } + if(pr.isSet("v") || pr.isSet("version")) + { + flags=P_VERSION; + return true; + } + if((pr.isSet("n") && pr.isValueSet("n", true)) || (pr.isSet("name") && pr.isValueSet("name", true))) + flags+=P_NAME; + if((pr.isSet("s") && pr.isValueSet("s", true)) || (pr.isSet("syntax") && pr.isValueSet("syntax", true))) + flags+=P_SYNTAX; + if((pr.isSet("e") && pr.isValueSet("e", true)) || (pr.isSet("expire") && pr.isValueSet("expire", true))) + flags+=P_EXPIRE; + if(pr.isSet("p") || pr.isSet("private")) + flags+=P_PRIVATE; + if(pr.isSet("g") || pr.isSet("guest")) + flags+=P_PRIVATE; + } + catch(const int& e) { + return false; + } + + return true; +} + +void showLicence() +{ + std::cout << std::endl << + "Copyright (C) 2011 Théophile BASTIAN (aka. Tobast) " << std::endl << + "This program is free software: you can redistribute it and/or modify " << std::endl << + "it under the terms of the GNU General Public License as published by " << std::endl << + "the Free Software Foundation, either version 3 of the License, or " << std::endl << + "(at your option) any later version. " << std::endl << + std::endl << + "This program is distributed in the hope that it will be useful, " << std::endl << + "but WITHOUT ANY WARRANTY; without even the implied warranty of " << std::endl << + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " << std::endl << + "GNU General Public License for more details. " << std::endl << + std::endl << + "You should have received a copy of the GNU General Public License " << std::endl << + "along with this program. If not, see http://www.gnu.org/licenses/gpl.txt." << std::endl << std::endl; +} +void showHelp() +{ + std::cout << MANPAGE_SHORT << std::endl; +} +void showVersion() +{ + std::cout << std::endl + << "pastebincl by BASTIAN Théophile (aka Tobast) v" << SOFT_VERSION << std::endl + << "Contact: or contact feature at http://tobast.fr/" << std::endl + << "Error report: " << std::endl << std::endl; +} + +CurlPost* preparePostRequest(const unsigned& flags, const ParameterRead& pr) +{ + // TODO! } diff --git a/func.h b/func.h index 2294e35..ebf5c47 100644 --- a/func.h +++ b/func.h @@ -35,8 +35,18 @@ #define DEF_FUNCTION #include +#include +#include +#include "data.h" -bool initParameterRead(ParameterRead& pr); +bool initParameterRead(ParameterRead& pr, unsigned& flags); +bool checkParameterRead(ParameterRead& pr, unsigned& flags); + +void showLicence(); +void showHelp(); +void showVersion(); + +CurlPost* preparePostRequest(const unsigned& flags, const ParameterRead& pr); #endif//DEF_FUNCTION diff --git a/main.cpp b/main.cpp index 14e80f6..0285a53 100644 --- a/main.cpp +++ b/main.cpp @@ -32,10 +32,39 @@ */ #include "CurlPost.h" +#include "data.h" +#include "func.h" +#include +#include int main(int argc, char** argv) { - CurlPost::init(); + + try { + ParameterRead pr(argc,argv); + unsigned parameterFlags=0; + + if(!initParameterRead(pr, parameterFlags)) + { + std::cerr << "FATAL ERROR: Bad parameters. See pastebincl -h for more help." << std::endl; + throw 42; + } + + if(parameterFlags & P_LICENCE) + showLicence(); + else if(parameterFlags & P_HELP) + showHelp(); + else if(parameterFlags & P_VERSION) + showVersion(); + else + { + // Here we start real stuff! + CurlPost::init(); + CurlPost::clean(); + } + } + catch(...) {} + return 0; }