3 Commit-ok 3096185814 ... 8fd86b9b91

Szerző SHA1 Üzenet Dátum
  David Blue 8fd86b9b91 Parser is now a back-end class 9 éve
  David Blue 8c70c99005 Adding code to handle paging text. 9 éve
  David Blue 1335424022 Added a pager class which is going to take a block of text and spit out text that can be easily broken down into multiple screen.s 9 éve
7 módosított fájl, 282 hozzáadás és 6 törlés
  1. 1 1
      .kdev4/BIBISH.kdev4
  2. 6 4
      cmake/Sources.cmake
  3. 112 0
      src/back/parser.cpp
  4. 42 0
      src/back/parser.h
  5. 1 1
      src/front/interface.cpp
  6. 79 0
      src/front/pager.cpp
  7. 41 0
      src/front/pager.h

+ 1 - 1
.kdev4/BIBISH.kdev4

@@ -23,4 +23,4 @@ Type=GCC
 VersionControlSupport=kdevgit
 
 [SourceFileTemplates]
-LastUsedTemplate=/home/david/.local/share/kdevfiletemplates/template_descriptions/cpp_basic.desktop
+LastUsedTemplate=/home/david/.kde4/share/apps/kdevfiletemplates/template_descriptions/cpp_basic.desktop

+ 6 - 4
cmake/Sources.cmake

@@ -1,12 +1,14 @@
-SET (backend_src ${CMAKE_CURRENT_SOURCE_DIR}/src/back/library.cpp
-		 ${CMAKE_CURRENT_SOURCE_DIR}/src/back/passage.cpp		 
+SET (backend_src ${CMAKE_CURRENT_SOURCE_DIR}/src/front/parser.cpp
+                 ${CMAKE_CURRENT_SOURCE_DIR}/src/back/library.cpp
+		 ${CMAKE_CURRENT_SOURCE_DIR}/src/back/passage.cpp		
+ 
 )
 
 source_group("backend_src" FILES ${backend_src})
 
 SET (frontend_src ${CMAKE_CURRENT_SOURCE_DIR}/src/front/display.cpp
-                  ${CMAKE_CURRENT_SOURCE_DIR}/src/front/parser.cpp
-		  ${CMAKE_CURRENT_SOURCE_DIR}/src/front/interface.cpp		
+		  ${CMAKE_CURRENT_SOURCE_DIR}/src/front/interface.cpp
+		  ${CMAKE_CURRENT_SOURCE_DIR}/src/front/pager.cpp
   
 )
 

+ 112 - 0
src/back/parser.cpp

@@ -0,0 +1,112 @@
+/*
+ * BIBISH Is [a] Bible Interactive SHell, a front-end for the SWORD Project
+ * inspired by debian's bible package
+ * Copyright (C) 2015  David "Judah's Shadow" Blue <yudahsshadow@gmx.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include "parser.h"
+
+#include <list>
+#include <string>
+#include <sstream>
+
+Parser::Parser() {
+    argumentCount = 0;
+}
+
+Parser::~Parser() {
+
+}
+
+int Parser::getNumberArguments() {
+    return argumentCount;
+}
+
+std::list< std::string > Parser::parseCommand(std::string command) {
+    std::list<std::string> tokenizedCommand;
+    std::string commandPart;
+    std::list<std::string> argumentPart;
+    std::list<std::string> parsedCommand;
+    
+    parsedCommand.clear();
+    argumentPart.clear();
+    
+    tokenizedCommand = tokenize(command);
+    
+    commandPart = tokenizedCommand.front();
+    tokenizedCommand.pop_front();
+    
+    parsedCommand.push_back(commandPart);
+    
+    if (tokenizedCommand.empty()) {
+        argumentCount = 0;
+        return parsedCommand;
+    } else {
+        argumentPart = tokenizedCommand;
+    }
+    
+    if (commandPart == ("show")) {
+        // TODO:Don't hardcode this  all we should have to parse is 
+        //making sure all the components of the argument
+        // are one for passing back to the interface
+        
+        while (!argumentPart.empty()) {
+            parsedCommand.push_back(argumentPart.front());
+            argumentPart.pop_front();
+        }
+    }
+    else if (commandPart == "select") {
+        //select has only one argument, stick it in line and ignore the rest
+        parsedCommand.push_back(argumentPart.front());
+    }
+    return parsedCommand;
+}
+
+
+std::list<std::string> Parser::tokenize(std::string string) {
+  tokens.clear();
+  if(string == "") {
+      return tokens;
+  } else {
+      tokens = split(string);
+      return tokens;
+  }
+}
+
+std::list<std::string> Parser::split(std::string string) {
+  std::istringstream tokenStream(string);
+  std::list<std::string> parts;  
+  parts.clear();
+  
+  // The following algorithm is based on the one found at
+  // http://www.cplusplus.com/faq/sequences/strings/split/#getline
+  
+  while (!tokenStream.eof()) {
+      // Yes I know this is normally "The Wrong Way(TM)" to do this
+      // since you shouldn't read past EOF, but getline is a bit
+      // werid about spacings on stringstreams
+      
+      std::string token;
+      std::getline(tokenStream, token, ' ');
+      
+      // do this even if we've already seen EOF.
+      parts.push_back(token);
+  }
+  
+  return parts;
+  
+}

+ 42 - 0
src/back/parser.h

@@ -0,0 +1,42 @@
+/*
+ * BIBISH Is [a] Bible Interactive SHell, a front-end for the SWORD Project
+ * inspired by debian's bible package
+ * Copyright (C) 2015  David "Judah's Shadow" Blue <yudahsshadow@gmx.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef PARSER_H
+#define PARSER_H
+
+#include <string>
+#include <list>
+
+class Parser
+{
+public:
+    Parser();
+    ~Parser();
+    int getNumberArguments();
+    std::list<std::string> tokenize(std::string string);
+    std::list<std::string> parseCommand(std::string command);
+private:
+    std::list<std::string> tokens;
+    int argumentCount;
+    
+    std::list<std::string> split(std::string string);
+};
+
+#endif // PARSER_H

+ 1 - 1
src/front/interface.cpp

@@ -26,10 +26,10 @@
 #include <markupfiltmgr.h>
 
 #include "interface.h"
-#include "parser.h"
 #include "display.h"
 #include "../back/passage.h"
 #include "../back/library.h"
+#include "../back/parser.h"
 
 void Interface::initalize() {
     configLines();

+ 79 - 0
src/front/pager.cpp

@@ -0,0 +1,79 @@
+/*
+ * BIBISH Is [a] Bible Interactive SHell, a front-end for the SWORD Project
+ * inspired by debian's bible package
+ * Copyright (C) 2015  David "Judah's Shadow" Blue <yudahsshadow@gmx.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include "pager.h"
+
+#include "../back/parser.h"
+
+#include <sys/types.h>
+#include <string>
+#include <list>
+
+
+Pager::Pager()
+{
+    this->cols = 0;
+    this->lines = 0;
+}
+
+// Pager::~Pager()
+// {
+//
+// }
+
+//This bad boy takes a raw string, and breaks it down into a list of
+//of lists (pages) of strings (lines).
+std::list< std::list<std::string> > Pager::getPagedText(std::string text) {
+    uint width = this->cols;
+    uint pageSize = this->lines;
+    int pageCount = 0;
+    int colCount = 0;
+    
+    Parser stringTokenizer;
+    std::list<std::string> words;
+    std::string currentWord;
+    
+    std::list<std::string> currentPage;
+    std::list<std::list <std::string> > pagedText;
+    
+    words = stringTokenizer.tokenize(text);
+    
+    while(!words.empty()) {
+        currentWord = words.front();
+        words.pop_front();
+        if(colCount + currentWord.length() + 1 <= width) {
+            currentPage.push_back(currentWord);
+            colCount += currentWord.length() + 1; //+1 for space
+        } else {
+            //TODO: Do stuff about words that are by themselves longer than
+            //TODO the width.
+            pagedText.push_back(currentPage);
+            currentPage.clear();
+            colCount = 0;
+        }
+    }
+    
+    return pagedText;
+}
+
+void Pager::setSize(uint rowSize, uint colSize) {
+    this->lines = rowSize;
+    this->cols = colSize;
+}

+ 41 - 0
src/front/pager.h

@@ -0,0 +1,41 @@
+/*
+ * BIBISH Is [a] Bible Interactive SHell, a front-end for the SWORD Project
+ * inspired by debian's bible package
+ * Copyright (C) 2015  David "Judah's Shadow" Blue <yudahsshadow@gmx.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef PAGER_H
+#define PAGER_H
+
+#include <sys/types.h>
+#include <string>
+#include <list>
+
+class Pager
+{
+public:
+    Pager();
+    ~Pager();
+
+    void setSize(uint rowSize,uint colSize = 80);
+    std::list<std::list<std::string> > getPagedText(std::string text);
+private:
+    uint lines;
+    uint cols;
+};
+
+#endif // PAGER_H