Main done, displays like version, etc. done, ready to begin real coding!
This commit is contained in:
parent
f8dafd3b1d
commit
3841a366fa
7 changed files with 156 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -56,6 +56,7 @@ class CurlPost {
|
|||
std::string execute();
|
||||
|
||||
static void init();
|
||||
static void clean();
|
||||
|
||||
protected:
|
||||
std::string url;
|
||||
|
|
26
Makefile
Normal file
26
Makefile
Normal file
|
@ -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)
|
||||
|
13
data.h
13
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
|
||||
|
||||
|
|
75
func.cpp
75
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: <contact@tobast.fr> or contact feature at http://tobast.fr/" << std::endl
|
||||
<< "Error report: <error-report@tobast.fr>" << std::endl << std::endl;
|
||||
}
|
||||
|
||||
CurlPost* preparePostRequest(const unsigned& flags, const ParameterRead& pr)
|
||||
{
|
||||
// TODO!
|
||||
}
|
||||
|
||||
|
|
12
func.h
12
func.h
|
@ -35,8 +35,18 @@
|
|||
#define DEF_FUNCTION
|
||||
|
||||
#include <parameterread/ParameterRead.h>
|
||||
#include <iostream>
|
||||
#include <CurlPost.h>
|
||||
#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
|
||||
|
||||
|
|
31
main.cpp
31
main.cpp
|
@ -32,10 +32,39 @@
|
|||
*/
|
||||
|
||||
#include "CurlPost.h"
|
||||
#include "data.h"
|
||||
#include "func.h"
|
||||
#include <parameterread/ParameterRead.h>
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue