5 Коммиты b4ec1cff02 ... 07f4513777

Автор SHA1 Сообщение Дата
  David 'Judah's Shadow' Blue 07f4513777 Adding descriptions to module lists. Cut out some "middle-man" processing and just return a list so we don't have to tokenize it now. 9 лет назад
  David 'Judah's Shadow' Blue a4d334e412 Prevent "" from being in the list of tokens rather than having to ignore them later. They seem to occur at the front and back of the lists so this also prevents double free crashes. 9 лет назад
  David 'Judah's Shadow' Blue b4e2b30f2a Move the page count into the loop unwinding the text so that the last page doesn't make you press enter to get back to the prompt. 9 лет назад
  David 'Judah's Shadow' Blue 9917eb7e53 Pages are now structs with content (the page) and linecount so the spacing works correctly for pages that don't take the whole screen. 9 лет назад
  David 'Judah's Shadow' Blue 6680bbadaf Refactoring more. Pages are now a string to reduce the amount of processing, pages are now printed to the screen all in one go. The current side effect though is there isn't a good way to get a line count. Fixing that later. 9 лет назад
6 измененных файлов с 52 добавлено и 41 удалено
  1. 15 10
      src/back/library.cpp
  2. 3 1
      src/back/library.h
  3. 4 2
      src/back/parser.cpp
  4. 9 1
      src/back/types.h
  5. 7 11
      src/front/interface.cpp
  6. 14 16
      src/front/pager.cpp

+ 15 - 10
src/back/library.cpp

@@ -21,30 +21,35 @@
 #include "library.h"
 
 #include <string>
+#include <list>
 
 #include <swmgr.h>
 #include <swmodule.h>
 
-std::string Library::getBibles() {
-    std::string moduleList = "";
-    std::string bibleType = "Biblical Texts";
-    std::string moduleType = "";
+std::list<std::string> Library::getBibles() {
+    std::string modules = "";
+    std::string module = "";
     sword::ModMap::iterator libraryIterator;
+    std::list<std::string> bibleList;
+    std::string modType;
 
     for(libraryIterator = swordLibrary->Modules.begin();
             libraryIterator != swordLibrary->Modules.end();
             libraryIterator++) {
 
         sword::SWModule *tempMod = libraryIterator->second;
-        moduleType = tempMod->getType();
-
-        if(moduleType == bibleType) {
-            moduleList += tempMod->getName();
-            moduleList += " ";
+        modType = tempMod->getType();
+
+        if(modType == sword::SWMgr::MODTYPE_BIBLES) {
+            module = tempMod->getDescription();
+            module += " - ";
+            module += tempMod->getName();
+            bibleList.push_front(module);
+            module = "";
         }
     }
 
-    return moduleList;
+    return bibleList;
 }
 
 void Library::setSwordLibrary(sword::SWMgr *library) {

+ 3 - 1
src/back/library.h

@@ -22,12 +22,14 @@
 #define LIBRARY_H
 
 #include <string>
+#include <list>
+
 #include <swmgr.h>
 
 class Library {
     public:
         //returns a space separated list of bibles in the current sword library
-        std::string getBibles();
+        std::list<std::string> getBibles();
 
         void setSwordLibrary(sword::SWMgr *library);
     private:

+ 4 - 2
src/back/parser.cpp

@@ -103,8 +103,10 @@ std::list<std::string> Parser::split(std::string string) {
       std::string token;
       std::getline(tokenStream, token, ' ');
 
-      // do this even if we've already seen EOF.
-      parts.push_back(token);
+      // do this even if we've already seen EOF. unless token is ""
+      if( token != "") {
+          parts.push_back(token);
+      }
   }
 
   return parts;

+ 9 - 1
src/back/types.h

@@ -27,9 +27,17 @@
 //Keep this around in case it is decided to keep lines as lists of words
 //instead of a block of text
 // typedef std::list<std::string> line;
+// typedef std::list<line> page;
 
 typedef std::string line;
-typedef std::list<line> page;
+struct Page {
+    int lineCount;
+    line content;
+};
+
+typedef Page page;
+
+
 
 //convience type so the project doesn't have to depend on glibc
 typedef unsigned int uint;

+ 7 - 11
src/front/interface.cpp

@@ -128,20 +128,17 @@ std::string Interface::processCommand(std::string command) {
 
         textPager.setSize(display.getSize());
         pagedText = textPager.getPagedText(text);
-        numPages = pagedText.size();
 
         while(!pagedText.empty()) {
-            curPage = pagedText.front();
             displayText = "";
-            numLines = curPage.size();
-            while(!curPage.empty()) {
-                curLine = curPage.front();
-                displayText += curLine;
-                curPage.pop_front();
-            }
-            pagedText.pop_front();
+            curPage = pagedText.front();
+            displayText = curPage.content;
+            numLines = curPage.lineCount;
+            numPages = pagedText.size();
+
             std::cout << displayText;
             display.displaySpacer(numLines);
+            pagedText.pop_front();
             if(numPages > 1) {
                 std::string dummy = "";
                 std::cout << "Press enter for next page";
@@ -158,8 +155,7 @@ std::string Interface::processCommand(std::string command) {
         int numBibles = 0;
 
         library.setSwordLibrary(swordLibrary);
-        tempBibles = library.getBibles();
-        bibles = worksParser.tokenize(tempBibles);
+        bibles = library.getBibles();
 
         if(bibles.empty()) {
             std::cerr <<  "No bibles found, please install in another frontend";

+ 14 - 16
src/front/pager.cpp

@@ -58,13 +58,6 @@ std::list<page> Pager::getPagedText(std::string text) {
         currentWord = words.front();
         words.pop_front();
 
-        if(currentWord == "") {
-            //We've got an empty word sometimes at the beginning of a passage
-            //ignore it and get the next one
-            currentWord = words.front();
-            words.pop_front();
-        }
-
         //Newlines appear within words and not always at EOL, so find them and
         //act accordingly.
         if(currentWord.find("\n") != std::string::npos) {
@@ -74,7 +67,7 @@ std::list<page> Pager::getPagedText(std::string text) {
                 //we've not got an EOL newline, so we need to split it again :/
                 std::string preEndl = currentWord.substr(0, endlPos);
                 currentLine += preEndl + "\n";
-                currentPage.push_back(currentLine);
+                currentPage.content += currentLine;
                 currentLine = "";
                 colCount = 0;
                 lineCount++;
@@ -104,11 +97,11 @@ std::list<page> Pager::getPagedText(std::string text) {
             currentWord = "";
             if(newLineCount > 0) {
                 currentLine += "\n";
-                currentPage.push_back(currentLine);
+                currentPage.content += currentLine;
                 currentLine = "";
                 if(newLineCount > 1) {
                     currentLine += "\n";
-                    currentPage.push_back(currentLine);
+                    currentPage.content +=currentLine;
                     currentLine = "";
                 }
                 lineCount += newLineCount;
@@ -117,7 +110,7 @@ std::list<page> Pager::getPagedText(std::string text) {
             //TODO: Do stuff about words that are by themselves longer than
             //TODO: the width.
             currentLine += "\n";
-            currentPage.push_back(currentLine);
+            currentPage.content += currentLine;
             currentLine = "";
             currentLine += currentWord + " ";
             colCount = currentWord.length() + 1;
@@ -125,22 +118,27 @@ std::list<page> Pager::getPagedText(std::string text) {
         }
 
         if(lineCount >= pageSize - 3) {
+            currentPage.lineCount = lineCount;
             pagedText.push_back(currentPage);
-            currentPage.clear();
+            currentPage.content = "";
             lineCount = 0;
+            currentPage.lineCount = lineCount;
         }
     }
 
     //Check to see if we have any lines that didn't get pushed and flush them in
-    if(currentLine.size() > 0) {
-        currentPage.push_back(currentLine);
+    if(currentLine.length() > 0) {
+        currentPage.content += currentLine + "\n";
         currentLine = "";
+        lineCount++;
     }
 
-    if(currentPage.size() > 0) {
+    if(currentPage.content.length() > 0) {
+        currentPage.lineCount = lineCount;
         pagedText.push_back(currentPage);
-        currentPage.clear();
+        currentPage.content = "";
         lineCount = 0;
+        currentPage.lineCount = lineCount;
     }
 
     return pagedText;