From fd589c53120cc3ec1d5d3529f8b8d6744c8926f2 Mon Sep 17 00:00:00 2001 From: Daniel Fiser Date: Tue, 6 Nov 2007 21:02:29 +0100 Subject: [PATCH] Few small changes. - Fixed debug.h to work properly when debugging is off. - factory from parser.h renamed to TokenFactory - Addded class TokensSvn for parsing svn diffs. - Added processing of arguments. - Added detaching from console after parsing input. --- src/debug.h | 3 ++- src/main.cpp | 28 ++++++++++++++++++++++++++-- src/parser/parser.h | 7 ++++++- src/parser/tokens.cpp | 17 ++++++++++++++--- src/parser/tokens.h | 7 ++++++- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/debug.h b/src/debug.h index 56146df..0a66997 100644 --- a/src/debug.h +++ b/src/debug.h @@ -32,9 +32,10 @@ #define MILESTONE(msg) DEBUG_HELPER(msg, "Milestone") #else #define DEBUG_HELPER(msg, type) - #define DB(msg, type) + #define DBG(msg) #define ERROR(msg, type) #define WARNING(msg, type) + #define MILESTONE(msg) #endif #endif diff --git a/src/main.cpp b/src/main.cpp index ca7850d..72c0f93 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ +#include #include +#include #include "diff/diff.h" #include "diff/text.h" @@ -6,14 +8,36 @@ #include "settings.h" #include "parser/parser.h" +using std::string; + int main(int argc, char *argv[]) { MILESTONE(""); MILESTONE("====== START QSHOWDIFF ======"); - Parser parser("git", new QTextStream(stdin)); - parser.parse(); + string input_type; + + if (argc != 2){ + std::cerr << "Error: At least one argument must be given." << std::endl; + return 1; + } + + input_type = argv[1]; + + try{ + Parser parser(input_type, new QTextStream(stdin)); + parser.parse(); + }catch(ParserException &e){ + std::cerr << "Error: Parser can't parse this type of input." << std::endl; + return 1; + } + + DBG("Detaching from console."); + if (daemon(0,0) != 0){ + std::cerr << "Error: Detaching failed. Proceeding without " + "detaching." << std::endl; + } QApplication app(argc, argv); diff --git a/src/parser/parser.h b/src/parser/parser.h index 9050e79..0b3eaaa 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -3,11 +3,15 @@ #include #include +#include #include #include "tokens.h" #include "../diff/diff.h" +class ParserException : std::exception { +}; + class Parser{ private: enum states{ @@ -64,7 +68,8 @@ class Parser{ Parser(std::string type, QTextStream *in) : _current_state(START_STATE), _in(in), - _cur_file(NULL), _cur_hunk(NULL) { _tokens = factory(type); } + _cur_file(NULL), _cur_hunk(NULL) + { _tokens = TokenFactory(type); if (_tokens == NULL) throw ParserException();} void parse(); }; diff --git a/src/parser/tokens.cpp b/src/parser/tokens.cpp index 5be2e53..10b6be4 100644 --- a/src/parser/tokens.cpp +++ b/src/parser/tokens.cpp @@ -1,11 +1,16 @@ #include "tokens.h" using std::string; -Tokens *factory(string type) +Tokens *TokenFactory(string type) { - Tokens *ret; + Tokens *ret = NULL; + + if (type == "git"){ + ret = new TokensGit(); + }else if (type == "svn"){ + ret = new TokensSvn(); + } - ret = new TokensGit(); DBG("factory(" << type << ") - ret: " << (long)ret); return ret; } @@ -45,3 +50,9 @@ TokensGit::TokensGit() : Tokens::Tokens("^diff --git a/([^ ]+) b/.*$", "^ .*$", "^\\+.*$", "^-.*$"){} + +TokensSvn::TokensSvn() : Tokens::Tokens("^Index: ([^ ]+).*$", + "^@@ -([0-9]+),.* \\+([0-9]+),.*$", + "^ .*$", + "^\\+.*$", + "^-.*$"){} diff --git a/src/parser/tokens.h b/src/parser/tokens.h index ab869b5..af53c49 100644 --- a/src/parser/tokens.h +++ b/src/parser/tokens.h @@ -44,5 +44,10 @@ class TokensGit : public Tokens{ TokensGit(); }; -Tokens *factory(std::string); +class TokensSvn : public Tokens{ + public: + TokensSvn(); +}; + +Tokens *TokenFactory(std::string); #endif -- 2.11.4.GIT