diff --git a/ConfigRead.cpp b/ConfigRead.cpp index 79fcc10..15d97f9 100644 --- a/ConfigRead.cpp +++ b/ConfigRead.cpp @@ -39,7 +39,7 @@ ConfigRead::ConfigRead(string filepath) { ifstream infile(filepath.c_str(), ios_base::in); if(!infile) - throw -1; + throw -42; // ANTI-ANSWER!!!1 string filecontent=unxor(infile); diff --git a/data.h b/data.h index 5c30242..cb91b27 100644 --- a/data.h +++ b/data.h @@ -35,6 +35,7 @@ #define DEF_DATA #include "data_devcode.h" // TODO before compile, check this file +#include "data_paramlist.h" // TODO REDEFINE YOUR OS HERE! #define UNIX @@ -53,7 +54,7 @@ #define DEFAULT_CONFIGPATH ".pastebinclrc" 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, P_USERGEN=256 + P_NAME=1, P_SYNTAX=2, P_PRIVATE=4, P_EXPIRE=8, P_GUEST=16, P_HELP=32, P_VERSION=64, P_LICENCE=128, P_USERGEN=256, P_SYNTAXLIST=512 }; #define SOFT_VERSION "0.1 INDEV" diff --git a/func.cpp b/func.cpp index 7d548c6..7d00fba 100644 --- a/func.cpp +++ b/func.cpp @@ -72,6 +72,11 @@ bool checkParameterRead(ParameterRead& pr, unsigned& flags) flags=P_VERSION; return true; } + if(pr.isSet("syntaxlist")) + { + flags=P_SYNTAXLIST; + 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))) @@ -118,6 +123,10 @@ void showVersion() << "Contact: or contact feature at http://tobast.fr/" << std::endl << "Error report: " << std::endl << std::endl; } +void showSyntaxList() +{ + std::cout << SYNTAX_LIST << std::endl; +} bool userGen() { @@ -191,25 +200,32 @@ CurlPost* preparePostRequest(const unsigned& flags, ParameterRead& pr, std::stri std::string getUserCode() { - ConfigRead cr(getConfigPath()); + try { + ConfigRead cr(getConfigPath()); - CurlPost* request=new CurlPost(PASTEBIN_USERCODE_URL); - - request->setPostData("api_dev_key", DEVELOPPER_CODE); - request->setPostData("api_user_name", cr.getUser()); - request->setPostData("api_user_password", cr.getPass()); + CurlPost* request=new CurlPost(PASTEBIN_USERCODE_URL); - std::string result=request->execute(); + request->setPostData("api_dev_key", DEVELOPPER_CODE); + request->setPostData("api_user_name", cr.getUser()); + request->setPostData("api_user_password", cr.getPass()); - delete request; + std::string result=request->execute(); - if(result.find("Bad API request") != std::string::npos) // FAIL! - { - std::cerr << result << std::endl; - throw -1; + delete request; + + if(result.find("Bad API request") != std::string::npos) // FAIL! + { + std::cerr << result << std::endl; + throw -1; + } + + return result; } - - return result; + catch(const int& e) { + if(e==-42) // Couldn't open file, let's assume no password was set + std::cerr << "Warning: couldn't open file " << getConfigPath() << ". Run 'pastebincl --usergen' to be able to post as a registered user." << std::endl; + } + return ""; } std::string getPasteContent() diff --git a/func.h b/func.h index d9a56a9..a1f6104 100644 --- a/func.h +++ b/func.h @@ -56,6 +56,7 @@ bool checkParameterRead(ParameterRead& pr, unsigned& flags); void showLicence(); void showHelp(); void showVersion(); +void showSyntaxList(); bool userGen(); diff --git a/main.cpp b/main.cpp index 0dd06b5..095a35f 100644 --- a/main.cpp +++ b/main.cpp @@ -57,6 +57,8 @@ int main(int argc, char** argv) showHelp(); else if(parameterFlags & P_VERSION) showVersion(); + else if(parameterFlags & P_SYNTAXLIST) + showSyntaxList(); else if(parameterFlags & P_USERGEN) { if(userGen()) diff --git a/manpage b/manpage index 5e6947b..68812a7 100644 --- a/manpage +++ b/manpage @@ -28,13 +28,21 @@ DESCRIPTION -s [syntax], --syntax=[syntax] Defines [syntax] as the syntax highlighting pattern of your text, eg. "c" or "lolcode" (see the full list on http://pastebin.com/). + To display the complete list, run "pastebincl --syntaxlist". + + --syntaxlist + Displays the complete list of "syntax" parameters (see "-s"). -e [expire_time], --expire [expire_time] Defines [expire_time] as the time before the paste expires. Possible values : - - TODO + - N = Never + - 10M = 10 Minutes + - 1H = 1 Hour + - 1D = 1 Day + - 1M = 1 Month -p, --private - Posts a private past instead of a public one. + Posts a private past instead of a public one. A private paste willn't be displayed in the latest pastes, neither than be indexed by search engines. -g, --guest Posts the paste as a guest. It's the default option if no configuration file was set.